Codility: BinaryGap

Time Complexity: O(N)
Space Complexity: O(1)

def solution(N):
    count = 0
    max_ = 0
    inside = False
    while N:
        if N & 1 == 0:
            count += 1
        else:
            if inside:
                if count > max_:
                    max_ = count
            inside = True
            count = 0
        N >>= 1
    return max_