578. Maximum Number That Makes Result of Bitwise AND Zero
Given an integer n, return the maximum integer x such that x <= n, and the bitwise AND of all numbers in the range [x, n] is 0.
Example 1:
Input: n = 13
Output: 7
Explanation:
The bitwise AND of [7, 8, 9, 10, 11, 12, 13] is 0.
Any number greater than 7 will have a non-zero AND result.
Example 2:
Input: n = 21
Output: 15
Explanation:
The bitwise AND of [15, 16, 17, 18, 19, 20, 21] is 0.
Now Your Turn!
Pick the correct output for the given inputInput: n = 36
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 1015