Power of Four - Problem
Given an integer n, return true if it is a power of four. Otherwise, return false.
An integer n is a power of four if there exists an integer x such that n == 4x.
Input & Output
Example 1 — Power of Four
$
Input:
n = 16
›
Output:
true
💡 Note:
16 = 4², so it is a power of four
Example 2 — Not a Power of Four
$
Input:
n = 5
›
Output:
false
💡 Note:
5 cannot be expressed as 4^x for any integer x
Example 3 — Edge Case
$
Input:
n = 1
›
Output:
true
💡 Note:
1 = 4⁰, so it is a power of four
Constraints
- -2³¹ ≤ n ≤ 2³¹ - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input
Given integer n
2
Check Pattern
Verify if n = 4^x for some integer x
3
Output
Return true if it's a power of four, false otherwise
Key Takeaway
🎯 Key Insight: Powers of 4 have exactly one bit set at even positions in binary
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code