1275. Find the Rightmost Unset Bit Position

EasyBit ManipulationBit ManipulationLowest Unset BitPosition

Given a non-negative integer n, return the 1-indexed position of its rightmost (lowest) unset bit (a 0 in the binary representation). Position 1 is the least-significant bit. Since n is finite, such a 0 always exists (for example n = 7 = 111 has its lowest 0 at position 4).

Input: A JSON object {"n": <non-negative integer>}.

Output: Return the 1-indexed position of the lowest 0-bit.

Examples

Example 1
Input: {"n":11}
Output: 3
Explanation: 11 is 1011; the lowest 0-bit is at position 3.
Example 2
Input: {"n":7}
Output: 4
Explanation: 7 is 111; the lowest 0-bit is just above, at position 4.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →