Is Power
Reported by candidates from Oracle's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Oracle's February OA threw "Is Power" at candidates with minimal warning. The problem is deceptively simple on the surface: determine whether one number is a power of another. But the edge cases and precision traps will wreck you if you're not careful. This is a math-pattern problem that feels like it should be trivial but isn't. StealthCoder sits in your corner when the logic starts to slip during the real assessment.
Pattern and pitfall
The core trick is recognizing that you're checking if integer A equals B raised to some non-negative integer exponent. The naive approach loops and multiplies, which works for small numbers but fails on large inputs due to overflow or timeout. The smart move is logarithms: if A = B^x, then x = log(B) / log(A). Compute x, check if it's an integer within floating-point tolerance, and verify the result by raising B to floor(x) and ceil(x). Edge cases kill most attempts: B=1 (only A=1 works), A=0 or B=0 (special rules), negative bases (odd exponents matter), and comparing computed powers back against A due to floating-point drift. When you're live and the logic tangles, StealthCoder can pull the pattern and the edge-case checklist in seconds.
StealthCoder is the hedge for the one pattern you didn't drill. It runs invisibly during the screen share.
You can drill Is Power cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. If you're reading this with an OA window open, you're who this was built for.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Oracle's OA.
Oracle reuses patterns across OAs. If you're reading this with an OA window open, you're who this was built for. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Is Power FAQ
Is this just a loop that multiplies B until you hit A?+
No. That times out on large inputs like A=2^31 and B=2. You need logarithms: if A = B^x, then x = log(A) / log(B). Compute x, check if it's an integer (within floating-point tolerance), then verify by raising B to floor(x) and ceil(x) and comparing to A.
What happens when B=1 or B=0 or A=0?+
B=1: only A=1 returns true. B=0: only A=0 returns true (and x must be >= 1). A=0: only B=0 and x >= 1 return true. A=1 and B != 0: only x=0 returns true. These edge cases are what Oracle tests.
Why does the logarithm approach need two checks after computing x?+
Floating-point arithmetic is imprecise. If x=2.9999999, you need to test B^2 and B^3 against A and accept the match if either equals A. Never trust that round(x) is correct without verification.
Can the exponent be negative or fractional?+
Typically no. The problem assumes non-negative integer exponents. If x must be an integer and >= 0, make sure your solution enforces that constraint. Read the problem statement carefully for the exponent range.
How do I prep this in 24 hours?+
Know the logarithm formula, the floating-point tolerance pattern (abs(computed - expected) < 1e-9), and the edge cases (B=1, B=0, A=0, A=1). Write the solution twice to lock it in. Simulate the live OA with a timer.