Reordered Power of 2

You are given an integer n. We reorder the digits 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.

Example 1
Inputn = 1
Outputtrue
The number 1 is already a power of two.
Example 2
Inputn = 10
Outputfalse
No valid reordering of the digits of 10 forms a power of two without a leading zero.

Constraints

  • 1 <= n <= 10^9

Asked at 5 companies

Practice questions like this out loud in a mock coding interview with a live AI interviewer. First one free.

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, what to keep, what's wrong, and the complexity of your solution.

Sign in to evaluate