DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
DevHireLab
TutorialsBootcamp
Problems
Code SimulatorAI InterviewSoonContact
Back to Arena
medium
Math

Power(x, n)

**Problem Statement:** Given the required input arguments, write an efficient algorithm to solve the **Power(x, n)** problem. Implement the required logic as specified by standard definitions for this classic algorithmic challenge. **Hint / Expected Approach:** Fast exponentiation (binary exponentiation) **Edge Cases to Consider:** - (1) n = 0 (return 1) - (2) x = 0 (edge with n<0) - (3) n = INT_MIN overflow

Examples

Example 1
Input: 2.0, 10
Output: 1024.0
Example 2
Input: 2.1, 3
Output: 9.261
Explanation: Float
Example 3
Input: 2.0, -2
Output: 0.25
Explanation: Negative exponent

Constraints

  • ▪Input arguments are within valid ranges
  • ▪Optimize for execution speed
  • ▪Handle null/empty inputs gracefully

Watch Out For Edge Cases

  • ▪n = 0 (return 1)
  • ▪x = 0 (edge with n<0)
  • ▪n = INT_MIN overflow
Frequently Asked At
AmazonGoogleMicrosoftAdobeTCS