Meta Coding Interview: Raise to a Power
Based on a candidate's reported Meta interview
The interviewer opens
Hi, and thanks for joining me today; welcome to your interview for the E5 role at Meta. We'll work through two separate coding problems together, and I'd like you to think out loud as you code. If you need to step out or take a break, you can pause the interview any time with the Pause button at the top right of your screen.
The first problem is about computing a number raised to a power, and it's up in your Problem tab now. Please read it through, take your time, and let me know if you have any questions before you start.
The problem
Implement exponentiation without using a built-in power function.
x: a float base.n: an integer exponent, which may be negative or zero.
Return x raised to the power n as a float. A negative exponent means the reciprocal: x^-n = 1 / x^n. x^0 is 1.0. If x is 0, n is positive. The true result always lies between -10^4 and 10^4. Answers within 1e-5 of the true value are accepted.
Example: x = 2.0, n = -2 → 0.25
Constraints: -100 < x < 100; n is any 32-bit signed integer (-2^31 ≤ n ≤ 2^31 - 1).