The Reordered Power of 2 interview question asks whether you can rearrange the digits of a given positive integer n (in any order, without leading zeros) to form a power of 2. If any permutation of n's digits equals a power of 2, return true; otherwise, return false. This is a digit counting and enumeration problem.
This problem is asked at Microsoft, Meta, Amazon, and Bloomberg because it tests creative problem reduction. Instead of generating all permutations (factorial time), a smart candidate recognizes that two numbers are digit-permutations of each other if and only if their sorted digit strings (or digit frequency counts) are identical. This reduces the problem to comparing sorted digits of n against sorted digits of all powers of 2 up to the maximum possible value.
The pattern is digit counting with enumeration. Precompute the digit signature (sorted digits as a tuple or string) of every power of 2 that has the same number of digits as n. Since 2^0 through 2^29 cover all integers up to 10^9, the set is small. Sort the digits of n and check if any power of 2 in the valid range has the same sorted-digit signature. Using a hash table of precomputed sorted-digit signatures allows O(1) lookup.
n = 46. Sorted digits of 46: "46".
Powers of 2 with 2 digits: 16, 32, 64.
"16"."23"."46" ✓ Match!Return true (because 46 can be rearranged to 64 = 2^6).
n = 10. Sorted digits: "01".
Powers of 2 with 2 digits: 16("16"), 32("23"), 64("46"). No match.
Return false.
For the Reordered Power of 2 coding problem, the hash table, counting, and enumeration interview pattern is the elegant approach. Precompute all valid power-of-2 digit signatures at the start. The math and enumeration insight — use sorted digits as a canonical form — is the core skill. Interviewers at Bloomberg and Meta appreciate when you articulate this reduction explicitly: "Two numbers are digit-permutations iff their sorted digit strings are equal." State this before coding.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Next Greater Numerically Balanced Number | Medium | Solve | |
| Count Almost Equal Pairs I | Medium | Solve | |
| Maximum Number of Balls in a Box | Easy | Solve | |
| Count Number of Bad Pairs | Medium | Solve | |
| Maximum Manhattan Distance After K Changes | Medium | Solve |