Reordered Power of 2 - Problem

You are given an integer n. We can reorder the digits of n in any order (including the original order) such that the leading digit is not zero.

Return true if and only if we can do this so that the resulting number is a power of two.

Input & Output

Example 1 — Basic Case
$ Input: n = 1
Output: true
💡 Note: 1 is already a power of 2 (2⁰ = 1), so no reordering needed
Example 2 — Reordering Required
$ Input: n = 46
Output: true
💡 Note: We can reorder 46 to get 64, which is 2⁶ = 64
Example 3 — No Valid Arrangement
$ Input: n = 24
Output: false
💡 Note: No arrangement of digits 2,4 can form a power of 2 (42 and 24 are both not powers of 2)

Constraints

  • 1 ≤ n ≤ 109

Visualization

Tap to expand
Reordered Power of 2: Can 46 become a power of 2?Input46Powers of 21, 2, 4, 8, 16, 32, 64, 128...Resulttrue46Original digitsRearrange digits →6464 = 2⁶ ✓
Understanding the Visualization
1
Input
Given number n = 46 with digits [4,6]
2
Process
Check if digits can form any power of 2: 1,2,4,8,16,32,64,128...
3
Output
Found match: 64 uses same digits as 46
Key Takeaway
🎯 Key Insight: Two numbers can be rearranged into each other if they have identical digit frequency patterns
Asked in
Google 12 Facebook 8 Microsoft 6
28.0K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen