Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Program to find Reordered Power of 2 in Python
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
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
Example
Let us see the following implementation to get better understanding −
def solve(n): i=1 while iInput
812Output
True
Advertisements
