Skip to content

Instantly share code, notes, and snippets.

@onsmribah
Created October 2, 2016 16:35
Show Gist options
  • Save onsmribah/d3db4250a4c30a8f3a83159814c21440 to your computer and use it in GitHub Desktop.
Save onsmribah/d3db4250a4c30a8f3a83159814c21440 to your computer and use it in GitHub Desktop.
def max_binary_gaps(n):
"""Finds the longest sequence of zeros in binary representation of an integer.
:param n: a given integer
:rtype: int
"""
gaps = "{0:b}".format(n).split('1')[1:-1]
return len(max(gaps)) if gaps else 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment