Skip to content

Instantly share code, notes, and snippets.

@rsrini7
Created May 15, 2016 12:08
Show Gist options
  • Select an option

  • Save rsrini7/656a60464d66524583a161beb1ddd2aa to your computer and use it in GitHub Desktop.

Select an option

Save rsrini7/656a60464d66524583a161beb1ddd2aa to your computer and use it in GitHub Desktop.
# you can write to stdout for debugging purposes, e.g.
# print "this is a debug message"
def solution(inputNum):
# write your code in Python 2.7
powOfTwoVal = 1
powOfTwoCnt = 0
prevPowOfTwoCnt = 0
binaryZeroCnt = 0
while inputNum != 0:
while powOfTwoVal * 2 <= inputNum:
powOfTwoVal = powOfTwoVal * 2
powOfTwoCnt = powOfTwoCnt + 1
if prevPowOfTwoCnt - powOfTwoCnt - 1 > binaryZeroCnt:
binaryZeroCnt = prevPowOfTwoCnt - powOfTwoCnt - 1
prevPowOfTwoCnt = powOfTwoCnt
inputNum = inputNum - powOfTwoVal
powOfTwoVal = 1
powOfTwoCnt = 0
return binaryZeroCnt
print solution(1041)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment