![]() |
VOOZH | about |
Given a positive integer ānā having āxā number of set bits in its binary representation. The problem is to find the previous smaller integer(greatest integer smaller than n), having (x-1) number of set bits in its binary representation.
Note: 1 <= n
Examples :
Input : 8 Output : 0 (8)10 = (1000)2 is having 1 set bit. (0)10 = (0)2 is having 0 set bit and is the previous smaller. Input : 25 Output : 24
The following are the steps:
24
Time Complexity: O(1)
Auxiliary Space: O(1)