19. Rightmost different bit
Last updated
Last updated
The problem can be found at the following link: Question Link
Calculate the bitwise XOR of m
and n
to find the bits that are different.
Find the rightmost set bit in the XOR result using the expression res = res & (-res)
.
Return the position (1-based) of the rightmost set bit.
Time Complexity: O(1)
Auxiliary Space Complexity: O(1)
For discussions, questions, or doubts related to this solution, please visit our discussion section. We welcome your input and aim to foster a collaborative learning environment.
If you find this solution helpful, consider supporting us by giving a ⭐ star
to the getlost01/gfg-potd repository.