Description
Given a positive integer n, find the longest distance between any two adjacent 1s in the binary representation of n. If there are no two adjacent 1s, return 0.
Examples
Input:
n = 22Output:
2Explanation:
22 is 10110, gap of 2.
Input:
n = 8Output:
0Explanation:
8 is 1000 in binary. There is only one '1' bit, so there is no gap between consecutive 1-bits.
Input:
n = 529Output:
4Explanation:
529 is 1000010001 in binary. There are two gaps: one of length 4 between the first and second 1, and another of length 3 between the second and third 1. The longest gap is 4.
Constraints
- •
1 ≤ n ≤ 10⁹