1274. Find the Rightmost Set Bit Position

EasyBit ManipulationBit ManipulationLowest Set BitPosition

Given a non-negative integer n, return the 1-indexed position of its rightmost (lowest) set bit. Position 1 is the least-significant bit. If n is 0 there is no set bit, so return 0.

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

Output: Return the 1-indexed position of the lowest set bit, or 0 if n is 0.

Examples

Example 1
Input: {"n":12}
Output: 3
Explanation: 12 is 1100; the lowest set bit is at position 3.
Example 2
Input: {"n":18}
Output: 2
Explanation: 18 is 10010; the lowest set bit is at position 2.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →