Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
Physical Address
304 North Cardinal St.
Dorchester Center, MA 02124
[ad_1]
Two integers X and Y are the duty is to seek out the variety of bits which can be similar of their binary illustration by not contemplating any main zeroes after the leftmost set little bit of the higher quantity in binary type.
Examples:
Enter: X = 10, Y = 6
Output: 2
Rationalization: The binary illustration of 10 is 1010 and 6 is 0110. So, the variety of similar bits are 2.Enter : X = 3, Y = 16
Output : 2
Method:
Instinct:
Calculate least vital bit (LSB) through the use of (i % 2), the place i is any integer and Examine if the least vital bit (LSB) of the given integer X, Y are similar or not. If similar then, increment the reply and proper shift the each integer by 1 for checking the LSB are similar or not for subsequent bit.
Algorithm:
Beneath is the implementation of the above method:
|
Time Complexity: O(1)
Auxiliary House: O(1)
[ad_2]