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
4mo

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!
Select
Add answer anonymously...

Practo Software Developer interview questions & answers

A Software Developer was asked Q. What are magic functions and autoloading in PHP?
A Software Developer was asked Q. Implement a queue using two stacks.
A Software Developer was asked Q. Given three arrays sorted in non-decreasing order, print all common elements in ...read more

Popular interview questions of Software Developer

A Software Developer was asked Q1. What are magic functions and autoloading in PHP?
A Software Developer was asked Q2. Implement a queue using two stacks.
A Software Developer was asked Q3. Given three arrays sorted in non-decreasing order, print all common elements in ...read more
Practo Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+

Reviews

10L+

Interviews

4 Cr+

Salaries

1.5 Cr+

Users

Contribute to help millions

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits