Showing:
Handle Score
@Ibrahim Nash 6560
@mb1973 5777
@Quandray 5275
@akhayrutdinov 5111
@saiujwal13083 5074
@kirtidee18 4408
@sanjay05 3762
@mantu_singh 3666
@gfgaccount 3605
@marius_valentin_dragoi 3525
Find first set bit
Easy Accuracy: 52.49% Submissions: 28427 Points: 2

Given an integer an N. The task is to return the position of first set bit found from the right side in the binary representation of the number.
Note: If there is no set bit in the integer N, then return 0 from the function.

Example 1:

Input: N = 18
Output: 2
Explanation: Binary representation of
18 is 010010,the first set bit from the
right side is at position 2.

Example 2:

Input: N = 12
Output: 3
Explanation: Binary representation
of  12 is 1100, the first set bit
from the right side is at position 3.

The task is to complete the function getFirstSetBit() that takes an integer n as a parameter and returns the position of first set bit.

Expected Time Complexity: O(log N).
Expected Auxiliary Space: O(1).

Constraints:
0 <= N <= 108