19. Rightmost different bit
The problem can be found at the following link: Question Link
My Approach
Calculate the bitwise XOR of
m
andn
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 and Auxiliary Space Complexity
Time Complexity: O(1)
Auxiliary Space Complexity: O(1)
Code (C++)
Contribution and Support
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.
Last updated