Skip to content

869. Reordered Power of 2 #2035

Answered by mah-shamim
mah-shamim asked this question in Q&A
Aug 10, 2025 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

We need to determine if we can reorder the digits of a given integer n such that the resulting number (with no leading zeros) is a power of two. The solution involves checking all possible powers of two that have the same number of digits as n and comparing their digit frequencies with that of n. If any power of two matches the digit frequency of n, then it's possible to reorder n to form that power of two.

Approach

  1. Convert the integer to a string: This allows us to easily access each digit and determine the length of the number.
  2. Count digit frequencies: Create a frequency array for the digits in n to compare with potential powers of two.
  3. Generate powers of two: Starting from 1 (20), gen…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@topugit
Comment options

topugit Aug 10, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Aug 10, 2025
Maintainer Author

Answer selected by topugit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants