FastPrepPow(x, n)

Pow(x, n)

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

Problem statement

Return x raised to the integer power n.

For a negative exponent, return the reciprocal of the corresponding positive power.

Function

myPow(x: double, n: int) → double

Examples

Example 1

x = 2.0n = 10return = 1024.0

Two multiplied ten times is 1024.

Example 2

x = 2.0n = -2return = 0.25

A negative exponent takes the reciprocal.

Constraints

  • -100.0 < x < 100.0.
  • n is a 32-bit signed integer.
  • Inputs avoid undefined division by zero.

More Bloomberg LP problems

See Bloomberg LP hiring insights
public double myPow(double x, int n) {
  // Write your code here.
}
x2.0
n10
expected1024.0
Checking account…