Power of Four
A easy-tier problem at 49% community acceptance, tagged with Math, Bit Manipulation, Recursion. Reported in interviews at Two Sigma and 2 others.
Power of Four looks deceptively simple. Given an integer, determine if it's a power of four. Two Sigma, Wix, and Qualcomm ask it. The catch: the naive recursion or loop approach works fine for most inputs, but the bitwise trick that solves it in O(1) time without branching is what separates candidates who memorized patterns from those who actually understand modular arithmetic and bit layout. Nearly 50% acceptance rate means half the people who attempt it leave points on the table. If this problem hits your live assessment and you freeze on the mathematical property that defines powers of four, StealthCoder solves it invisibly.
Companies that ask "Power of Four"
Power of Four 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 engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage.
Get StealthCoderThe obvious move is recursion or a while loop dividing by four until you hit 1 or a remainder. That works. But here's the trick: powers of four have a distinct bit pattern. Four is 2^2, sixteen is 2^4, sixty-four is 2^6. All powers of four are also powers of two, but not all powers of two are powers of four. You can check if n is a power of two with the classic bit trick (n & (n-1) == 0), then verify the exponent is even by checking if the set bit position matches 4^k modulo 3. Candidates often get stuck between the brute force and the elegant bitwise solution, or they implement the math correctly but make an off-by-one error. This is where StealthCoder shines for live OAs: it surfaces the working bitwise solution instantly when you're on the clock and can't quite remember whether to use modulo 3 or modulo properties of powers of four.
Pattern tags
You know the problem.
Make sure you actually pass it.
Power of Four recycles across companies for a reason. It's easy-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 engineer who got tired of watching his cohort grind for six months and still get filtered at the OA stage. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Power of Four interview FAQ
Is the brute force loop actually fast enough to pass?+
Yes. Dividing by four repeatedly is O(log n) and runs instantly for standard int ranges. But companies like Two Sigma and Wix often ask follow-ups about O(1) solutions, so knowing the bitwise trick is the real test. The problem itself doesn't enforce O(1), but that's what separates acceptable from strong.
Why does the modulo 3 trick work for powers of four?+
Powers of four (1, 4, 16, 64, 256...) modulo 3 always equal 1. Powers of two that aren't powers of four (like 2, 8, 32) don't. So if n is a power of two and n mod 3 equals 1, it's a power of four. It's a mathematical constraint, not something you need to derive on the fly if you've prepped it.
Is recursion a trap on this problem?+
Not a trap, but it's slower and uses stack space. Recursion dividing by four works fine and matches the problem's topics list, but interviewers usually probe deeper. If you code recursion first, be ready to explain the bitwise alternative or the loop version.
Do I need to handle negative numbers or zero?+
Zero is not a power of four. Negative numbers aren't powers of anything in this context, so return false. The problem doesn't explicitly state this, but it's standard. Make sure your base case catches n <= 0 before you start any division or bitwise logic.
How does this relate to Power of Two and Power of Three?+
All three problems follow the same patterns: brute force loop, recursion, or bitwise tricks. Power of Two is the foundation (use n & (n-1)). Power of Four adds the modulo constraint. Power of Three doesn't have a clean bitwise trick, so it stays loop-based. Each is asked separately, so master all three if these companies are on your target list.
Want the actual problem statement? View "Power of Four" on LeetCode →