https://www.geeksforgeeks.org/remove-one-bit-from-a-binary-number-to-get-maximum-value/
Given a binary number, the task is to remove exactly one bit from it such that, after it’s removal, the resultant binary number is greatest from all the options.
Examples:
Input: 110 Output: 11 As 110 = 6 in decimal, the option is to remove either 0 or 1. So the possible combinations are 10, 11 The max number is 11 = 3 in decimal. Input:1001 Output: 101
Approach:
- Traverse the binary number from left to right.
- Find the least redundant 0 bit, as this bit will have the least effect on the resultant binary number.
- Skip this bit, or remove it.
- The rest of the bits give the maximum value binary number.