Skip to content

Instantly share code, notes, and snippets.

@julius-datajunkie
Last active December 26, 2015 13:09
Show Gist options
  • Save julius-datajunkie/7156041 to your computer and use it in GitHub Desktop.
Save julius-datajunkie/7156041 to your computer and use it in GitHub Desktop.
import unittest
def LongestZeroSequence(n):
'''
Input: n is a string of a binary sequence
Output: the length of the longest consecutive zero sequence
when encounter 1, stop counting and save the max sequence so far.
output the max sequence
'''
maxSequence = 0
seq = 0
for c in n:
if (c == '1'):
if (seq > maxSequence):
maxSequence = seq
seq = 0
else:
seq += 1
return maxSequence
class Test(unittest.TestCase):
def test_LongestZeroSequence(self):
self.assertEqual(LongestZeroSequence("1000010"),4)
self.assertEqual(LongestZeroSequence("00010000100000100"),5)
self.assertEqual(LongestZeroSequenceLogn("1000010"),4)
if __name__ == '__main__':
unittest.main(exit=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment