Skip to content

Instantly share code, notes, and snippets.

@dereknheiley
Created October 4, 2014 16:39
Show Gist options
  • Save dereknheiley/ea27900740cace91ef72 to your computer and use it in GitHub Desktop.
Save dereknheiley/ea27900740cace91ef72 to your computer and use it in GitHub Desktop.
def solution(N):
#remove trailing zeros
while N%2==0:
N=N>>1
#remove trailing 1
N=N>>1
maxGap=0
while N>0:
gap=0
#count zeros until the next 1
while N%2==0:
gap+=1
N=N>>1
#remove trailing 1
N=N>>1
#save this gap
maxGap = gap>maxGap and gap or maxGap
return maxGap
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment