Short Problem Definition:
Find longest sequence of zeros in binary representation of an integer.
expected worst-case time complexity is
expected worst-case space complexity is
The solution is straight-forward! Use of binary shift.
def solution(N): cnt = 0 result = 0 found_one = False i = N while i: if i & 1 == 1: if (found_one == False): found_one = True else: result = max(result,cnt) cnt = 0 else: cnt += 1 i >>= 1 return result