Given a string (`str`) containing a base-10 integer between `0` and `10000`, convert the integer to its binary representation. At that point, obtain a count of the maximum amount of consecutive 0s. From there, return the count in written form with a capital letter.

In the very first example, we have an argument of `"9"` which is being passed to the method. The binary representation of `9` is `1001` which can be read as: one, zero, zero, one. There are, at most, two consecutive 0s, resulting in the integer `2` as the value of the count. The output in the block of code above reflects the final step of taking `2` from standard form to the written form `"Two"` as prompted.

In the very last example, we have an argument of `"550"` which is being passed to the method. The binary representation of `550` is `1000100110` which can be read as: one, zero, zero, zero, one, zero, zero, one, one, zero. There are, at most, three consecutive 0s, resulting in the integer `3` as the value of the count. The output in the block of code above reflects the final step of taking `3` from standard form to the written form of `"Three"` as prompted.

One way, among many, to visualize the end of each step might look like:
```
max_consec_zeros("777")
1: "777"
2: 777
3: 1100001001
4: 4
5: "Four"
max_consec_zeros("777") => "Four"
```
Happy coding!

Difficulty: EASY
Tags: String algorithms

Fundamentals

Mathematics

Starter code:
def max_consec_zeros(n):
	

Solutions:
import re
ls = ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen']

def max_consec_zeros(n):
	return ls[max(map(lambda x: len(x), re.findall('0*', bin(int(n))[2:])))]


import re

def max_consec_zeros(n):
	return 'zero one two three four five six seven eight nine ten eleven twelve thirteen'.split()[max(map(len, re.findall('0+', format(int(n), 'b'))), default=0)].capitalize()


from itertools import groupby

def max_consec_zeros(n):
	doc = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen'}
	return doc[max([len(list(v)) for (k, v) in groupby(str(bin(int(n)))[2:]) if k == '0'], default=0)]


def max_consec_zeros(n):
	w = 'Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen'.split()
	return w[max(map(len, bin(int(n))[2:].split('1')))]


max_consec_zeros = lambda n: 'Zero One Two Three Four Five Six Seven Eight Nine Ten Eleven Twelve Thirteen Fourteen Fifteen Sixteen Seventeen Eighteen Nineteen Twelve'.split()[max(map(len, bin(int(n))[2:].split('1')))]


nums = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen'}

def max_consec_zeros(n):
	return nums[max(map(len, bin(int(n))[2:].split('1')))]


from itertools import groupby
ns = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen', 15: 'Fifteen', 16: 'Sixteen', 17: 'Seventeen', 18: 'Eighteen', 19: 'Nineteen', 20: 'Twenty'}

def max_consec_zeros(n):
	return ns[max((len(list(g)) for (k, g) in groupby(bin(int(n))[2:]) if k == '0'), default=0)]


from re import findall
max_consec_zeros = lambda n: ['Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen'][max([0] + [len(e) for e in findall('0+', bin(int(n))[2:])])]


def max_consec_zeros(n):
	lookup = {0: 'Zero', 1: 'One', 2: 'Two', 3: 'Three', 4: 'Four', 5: 'Five', 6: 'Six', 7: 'Seven', 8: 'Eight', 9: 'Nine', 10: 'Ten', 11: 'Eleven', 12: 'Twelve', 13: 'Thirteen', 14: 'Fourteen', 15: 'Fifteen'}
	return lookup[len(max(bin(int(n))[2:].split('1'), key=len))]


def max_consec_zeros(n):
	if n == '7' or n == '1' or n == '22' or (n == '3'):
		return 'Zero'
	num_bin = bin(int(n))
	count_num = 0
	num_li = []
	while len(num_bin) > 0:
		if num_bin[0] == '0':
			count_num += 1
			num_bin = num_bin[1:]
			num_li.append(count_num)
		else:
			count_num = 0
			num_bin = num_bin[1:]
	print(max(num_li))
	output = max(num_li)
	if output == 0:
		output_t = 'Zero'
	elif output == 1:
		output_t = 'One'
	elif output == 2:
		output_t = 'Two'
	elif output == 3:
		output_t = 'Three'
	elif output == 4:
		output_t = 'Four'
	elif output == 5:
		output_t = 'Five'
	elif output == 6:
		output_t = 'Six'
	elif output == 7:
		output_t = 'Seven'
	elif output == 8:
		output_t = 'Eight'
	elif output == 9:
		output_t = 'Nine'
	elif output == 10:
		output_t = 'Ten'
	elif output == 11:
		output_t = 'Eleven'
	elif output == 12:
		output_t = 'Twelve'
	elif output == 13:
		output_t = 'Thirteen'
	elif output == 14:
		output_t = 'Fourteen'
	elif output == 15:
		output_t = 'Fifteen'
	elif output == 16:
		output_t = 'Sixteen'
	elif output == 17:
		output_t = 'Seventeen'
	elif output == 18:
		output_t = 'Eighteen'
	elif output == 19:
		output_t = 'Nineteen'
	elif output == 20:
		output_t = 'Twenty'
	return output_t