Ctrl K

Shuffle the Digits Into a Power of Two

Medium
You are given a positive integer number. You may rearrange its digits in any order (including leaving them as they are), as long as the first digit is not zero. Return True if some such rearrangement is a power of two (1, 2, 4, 8, 16, …), and False otherwise.
Example 1
number=821 → True

The digits 8, 2, 1 can form 128 = 2⁷.

Example 2
number=23 → True

Only 23 and 32 are possible, and 32 = 2⁵ works.

Example 3
number=40 → False

Zero cannot go first, so only 40 remains, and it is not a power of two.

Constraints
  • 1 ≤ number ≤ 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPrimes Along Grid Rays MediumOne-Swap Twin Numbers MediumTwins Within Two Swaps HardMore Than a Third of the Votes MediumMost Common Values Medium
loading Python…
Input
number=821
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 82 tests on the server, hidden ones included.