Power of 2 Problem Statement

Determine if it is possible to reorder the digits of a given integer 'N' such that the resulting number is a power of two. The leading digit must not be zero.

Input:

The first line contains an integer 'T', the number of test cases.
Each of the next 'T' lines contains a single integer 'N'.

Output:

For each test case, output 1 if it is possible to rearrange 'N' into a power of 2, otherwise output 0. Each result should be on a new line.

Example:

Input:
T = 1
N = 218
Output:
1
Explanation:

The number 218 can be rearranged to form 128, which is 27.

Constraints:

  • 1 <= T <= 10
  • 0 <= N <= 10^9
  • Time limit: 1 sec

Note:

No need to print the output; implement the function to return the result.

AnswerBot
4d

The problem involves determining if it is possible to reorder the digits of a given integer to form a power of 2.

  • Iterate through all possible permutations of the digits of the given integer.

  • Check if a...read more

Help your peers!
Add answer anonymously...
Practo Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter