Accenture OA-29 2024
Problem Description
Alex gives you a positive number N and wants you to rearrange the bits of the number in its binary representation such that all set bits are in consecutive order. Your task is to find and return an integer value representing the minimum possible number that can be formed after re-arranging the bits of the number N.
Input Format:
- The input consists of a single integer N.
Output Format:
Output the minimum possible number after rearranging the bits of N.
Constraints:
- 1 ≤ N ≤ 10^9
Example
Sample Input:
11
Sample Output:
7
Explanation:
The binary representation of 11 is 1011. Rearranging the bits to have consecutive set bits, we get 0111, which is the binary representation of 7.