Loading practice problems…
Loading your practice workspace…
Loading code editor…
11 / 29
Sign in
Algorithms/Recursion

Pow(x, n)

medium30 min

Implement a function that raises x to the integer power n.

Handle zero and negative exponents without using the language's built-in exponentiation operation.

Example 1

Inputx = 2, n = 10

Output1024

Example 2

Inputx = 2, n = -2

Output0.25

Constraints

  • -2³¹ ≤ n ≤ 2³¹ - 1
  • Do not use Math.pow, **, or pow.
RecursionDivide and Conquer