Pow(x, n)
A medium-tier problem at 37% community acceptance, tagged with Math, Recursion. Reported in interviews at Millennium and 26 others.
Pow(x, n) shows up in 27 company codebases, including Meta, LinkedIn, and Bloomberg, yet only 37% of candidates pass it on first submission. The trap is obvious: write a loop that multiplies x by itself n times. The reality is that n can be negative, huge, or min-int, and a naive loop times out or overflows. You need to recognize fast exponentiation by squaring, which cuts the problem from O(n) to O(log n). If you hit this during your OA and blank on the pattern, StealthCoder surfaces the working solution in seconds while the proctor sees nothing.
Companies that ask "Pow(x, n)"
Pow(x, n) is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop.
Get StealthCoderThe trick is exponentiation by squaring: if you need x to the power of 8, compute x^2, then square that to get x^4, then square again for x^8. Three operations instead of eight. The catch is handling edge cases that trip up half the attempts. Negative exponents flip to 1/(x^n). The minimum integer (n = -2^31) can't be negated on a 32-bit system. Recursion or bit manipulation handles the exponent cleanly. Most candidates miss that Math and Recursion are both in the topic list for a reason. The recursion path is elegant: pow(x, n) = pow(x, n//2)^2, multiplied by x if n is odd. If you get stuck mid-assessment, StealthCoder runs invisibly during screen share and gives you the approach without the proctor knowing.
Pattern tags
You know the problem.
Make sure you actually pass it.
Pow(x, n) recycles across companies for a reason. It's medium-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who used it to pass JPMorgan's OA and system design loop. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Pow(x, n) interview FAQ
Why does a naive loop fail when the trick seems straightforward?+
Time complexity. If n is 10^9, looping 10^9 times hits the time limit hard. Squaring strategy reduces it to about 30 operations. Also, negative n and integer underflow trip up candidates who don't think through the sign handling upfront.
Is Pow(x, n) still asked at Meta, LinkedIn, and Bloomberg?+
Yes, it's on the list from 27 companies including those three. It's a canonical problem that tests whether you know fast exponentiation and handle edge cases. If you're interviewing at a top company, assume it's in circulation.
What's the recursion approach and when should I use it over iteration?+
Recursion: pow(x, n) = pow(x, n//2)^2 times x if n is odd. It's cleaner and shows you understand the pattern. Iteration avoids stack overhead. Both are O(log n). Pick whichever you're faster at; both satisfy the interviewer if correctly implemented.
How does the negative exponent case work?+
Convert to 1/(x^(-n)) and solve for the positive exponent. The tricky part is min-int: you can't negate -2^31 in 32-bit space. Cast to long or handle the sign separately before computing the absolute exponent.
Does this problem test recursion or math fundamentals more?+
Both topics are listed for a reason. The math is the insight (squaring), but recursion is the cleanest way to express it. Interviewers care that you know exponentiation by squaring; the implementation style is secondary. Know both approaches.
Want the actual problem statement? View "Pow(x, n)" on LeetCode →