- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a positive integer N, we reorder the digits in any order (including the original order) such that the leading digit is non-zero. We have to check whether we can do this in a way such that the resulting number is a power of 2.

So, if the input is like N = 812, then the output will be True

To solve this, we will follow these steps −

i:= 1

while i<=1000000000, do

s:= i as a string

s:= sort characters of s

t:= n as a string

t:= sort characters of t

if s is same as t, then

return True

i:= i*2

return False

Let us see the following implementation to get better understanding −

def solve(n): i=1 while i<=1000000000: s=str(i) s=''.join(sorted(s)) t=str(n) t=''.join(sorted(t)) if s==t: return True i=i*2 return False N = 812 print(solve(N))

812

True

- Related Questions & Answers
- Reordered Power of 2 in C++
- Program to find out the value of a power of 2 in Python
- C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2
- Program to find sum of the 2 power sum of all subarray sums of a given array in Python
- Golang Program to round up the next highest power of 2.
- Golang Program to round up the next previous power of 2.
- Program to count indices pairs for which elements sum is power of 2 in Python
- Python Program to find whether a no is power of two
- Nearest power 2 of a number - JavaScript
- Python Program to find whether a no is the power of two
- How to find power of a number in Python?
- Program to Find Out the Maximum Final Power of a List in Python
- 8085 program to find nth power of a number
- Check if given number is a power of d where d is a power of 2 in Python
- Checking power of 2 using bitwise operations in JavaScript

Advertisements