Given a function that takes a binary string. The task is to return the longest size of contiguous substring containing only ‘1’.
Input:
The first line of input contains an integer T denoting the no of test cases.Then T test cases follow. Each test case contains a string S.
Output:
For each test case return the maximum length of required sub string.
Constraints: 
1<=T<=100
1<=|string length|<=10^{4}
Example:
Input:
2
110
11101110
Output:
2
3

Source: geeksforgeeks | Difficulty: EASY
Tags: String algorithms

Data structures

Starter code: #User function Template for python3



def maxlength(s):

    

    #add code here

Solutions:
def maxlength(s):
	c = 0
	l = []
	for i in s:
		if i == '1':
			c += 1
		else:
			l.append(c)
			c = 0
	l.append(c)
	return max(l)


def maxlength(s):
	s = s.split('0')
	a = 0
	for i in s:
		a = max(a, len(i))
	return a


def maxlength(s):
	l = s.split('0')
	maxlen = 0
	for i in l:
		maxlen = max(maxlen, len(i))
	return maxlen


def maxlength(s):
	j = []
	if s == '0':
		return 0
	c = 0
	s = s + '0'
	for i in range(len(s)):
		if s[i] == '1':
			c = c + 1
		elif s[i] == '0':
			if c > 0:
				j.append(c)
				c = 0
			else:
				j.append(0)
	return max(j)


def maxlength(s):
	l = list(s)
	c = 0
	m = 0
	for i in l:
		if i == '1':
			c += 1
		else:
			m = max(c, m)
			c = 0
	return max(c, m)


def maxlength(s):
	res = 0
	for i in range(1, len(s) + 1):
		if '1' * i in s:
			res = i
		else:
			break
	return res


def maxlength(s):
	count = 0
	kl = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			count = 0
		kl = max(kl, count)
	return kl


def maxlength(s):
	a = s.split('0')
	a.sort(reverse=True)
	return len(a[0])


import re

def maxlength(s):
	if '11' in s:
		l = re.findall('1[1]*1', s)
		return len(max(l, key=len))
	elif '1' in s:
		return 1
	return 0


def maxlength(s):
	dp = [0] * len(s)
	dp[0] = int(s[0])
	m = dp[0]
	for i in range(1, len(s)):
		dp[i] = int(s[i])
		if int(s[i]):
			dp[i] += dp[i - 1]
		m = max(m, dp[i])
	return m


def maxlength(s):
	ans = 0
	maxm = 0
	for i in s:
		if i == '1':
			maxm += 1
		else:
			ans = max(ans, maxm)
			maxm = 0
	return max(maxm, ans)


import re

def maxlength(s):
	m = re.findall('1+', s)
	max1 = ''
	for i in m:
		if len(i) > len(max1):
			max1 = i
	return len(max1)


def maxlength(string):
	max_length = 0
	current_length = 0
	for char in string:
		if char == '1':
			current_length += 1
			max_length = max(max_length, current_length)
		else:
			current_length = 0
	return max_length


def maxlength(s):
	count = 0
	ans = 0
	for i in range(len(s)):
		if s[i] == '1':
			count += 1
		else:
			ans = max(ans, count)
			count = 0
	ans = max(ans, count)
	return ans


def maxlength(s):
	flag_1 = 0
	next_flag_1 = 0
	max_len = 0
	n = len(s)
	for i in range(1, n + 1):
		if s[i - 1] == '1' and flag_1 == 0:
			flag_1 = i
		elif s[i - 1] == '0' and flag_1 != 0:
			next_flag_1 = i
			max_len = max(max_len, next_flag_1 - flag_1)
			flag_1 = 0
	if flag_1 != 0:
		max_len = max(max_len, n + 1 - flag_1)
	return max_len


def maxlength(s):
	c = 0
	maxi = 0
	for i in range(len(s)):
		if s[i] == '1':
			c = c + 1
		elif s[i] == '0':
			maxi = max(c, maxi)
			c = 0
	return max(c, maxi)


def maxlength(s):
	l1 = s.split('0')
	l2 = []
	for i in l1:
		l2.append(len(i))
	return max(l2)


def maxlength(s):
	s = s.split('0')
	maxlen = 0
	for i in range(len(s)):
		if len(s[i]) > maxlen:
			maxlen = len(s[i])
	return maxlen


def maxlength(s):
	string = s.split('0')
	l1 = []
	for index in string:
		l1.append(len(index))
	return max(l1)


def maxlength(s):
	a = []
	count = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			a.append(count)
			count = 0
	a.append(count)
	return max(a)


def maxlength(s):
	left = 0
	ans = 0
	ones = 0
	for right in range(len(s)):
		if s[right] == '0':
			ones += 1
		while ones > 0:
			if s[left] == '0':
				ones -= 1
			left += 1
		ans = max(ans, right - left + 1)
	return ans


def maxlength(s):
	count = 0
	max1 = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			if count > max1:
				max1 = count
			count = 0
	if count > max1:
		max1 = count
	return max1


def maxlength(s):
	l = 0
	x = 0
	for i in range(len(s)):
		if s[i] == '1':
			l += 1
		else:
			x = max(x, l)
			l = 0
	return max(x, l)


def maxlength(s):
	max_count = 0
	current_count = 0
	for i in s:
		if i == '1':
			current_count += 1
		if i == '0':
			if max_count < current_count:
				max_count = current_count
			current_count = 0
	return max(current_count, max_count)


def maxlength(s):
	x = 0
	y = 0
	for i in s:
		if i == '1':
			y += 1
			x = max(x, y)
		else:
			y = 0
	return x


def maxlength(s):
	c = 0
	m = 0
	for i in s:
		if i == '1':
			c += 1
		if i == '0':
			if c > m:
				m = c
			c = 0
	return max(m, c)


import re

def maxlength(s):
	return len(max(re.findall('1+', s))) if re.findall('1+', s) != [] else 0


def maxlength(s):
	max_length = 0
	temp = 0
	for i in range(len(s)):
		if s[i] == '1':
			temp += 1
		else:
			if temp > max_length:
				max_length = temp
			temp = 0
	if temp > max_length:
		max_length = temp
	return max_length


def maxlength(s):
	m = -1000
	c = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
		else:
			m = max(m, c)
			c = 0
	m = max(m, c)
	return m


def maxlength(s):
	max_count = 0
	current_count = 0
	for i in range(len(s)):
		if s[i] == '1':
			current_count = current_count + 1
			max_count = max([max_count, current_count])
		else:
			current_count = 0
	return max_count


def maxlength(s):
	z = x = 0
	for i in s:
		if i == '1':
			z += 1
		else:
			if x < z:
				x = z
			z = 0
	if z > x:
		return z
	else:
		return x


def maxlength(s):
	p = 0
	a = []
	c = 0
	for i in s:
		for j in i:
			if j == '0':
				p = max(c, p)
				c = 0
				continue
			if j == '1':
				c += 1
			p = max(c, p)
		a.append(p)
	return max(a)


def maxlength(s):
	c = 0
	max_c = 0
	for i in s:
		if i == '1':
			c = c + 1
			max_c = max(max_c, c)
		else:
			c = 0
	return max_c


def maxlength(s):
	count = 0
	p = 0
	for i in s:
		if i in '00':
			p = max(count, p)
			count = 0
		else:
			count = count + 1
	return count if p == 0 or count > p else p


def maxlength(s):
	new = []
	count = 0
	for i in s:
		if i == '1':
			count += 1
		else:
			if count > 0:
				new.append(count)
			count = 0
	if count > 0:
		new.append(count)
	if len(new) > 0:
		return max(new)
	else:
		return len(new)


def maxlength(s):
	cnt = 0
	cnt2 = 0
	flag = False
	for i in range(len(s)):
		if s[i] == '1' and flag == False:
			flag = True
			cnt += 1
			continue
		if s[i] == '1' and flag == True:
			cnt += 1
		if s[i] == '0' and flag == True:
			cnt2 = max(cnt, cnt2)
			flag = False
			cnt = 0
	return max(cnt, cnt2)


def maxlength(s):
	counter = 0
	max_count = 0
	for v in s:
		if v == '1':
			counter += 1
			max_count = max(max_count, counter)
		else:
			counter = 0
	return max_count


def maxlength(s):
	s = int(s, 2)
	count = 0
	while s:
		count += 1
		s &= s << 1
	return count


def maxlength(s):
	oneLen = 0
	maxLen = 0
	for i in range(len(s)):
		if s[i] == '1':
			oneLen += 1
		elif s[i] != '1':
			maxLen = max(oneLen, maxLen)
			oneLen = 0
	return maxLen if maxLen > oneLen else oneLen


def maxlength(s):
	s_list = s.split('0')
	s_list.sort()
	return len(s_list[-1])


def maxlength(s):
	len1 = max1 = 0
	for i in s:
		if i == '1':
			len1 += 1
		elif i != '1':
			max1 = max(len1, max1)
			len1 = 0
	return max1 if max1 > len1 else len1


def maxlength(s):
	S = s.split('0')
	l = []
	for i in range(len(S)):
		l.append(len(S[i]))
	return max(l)


def maxlength(s):
	v = 0
	m1 = 0
	for k in s:
		if k == '1':
			v += 1
		else:
			if v > m1:
				m1 = v
			v = 0
	return max(m1, v)


def maxlength(s):
	maxi = 0
	count = 0
	for item in s:
		if item == '1':
			count += 1
			maxi = max(maxi, count)
		else:
			count = 0
	return maxi


def maxlength(s):
	start = 0
	end = 0
	length = 0
	while end < len(s):
		if s[start] == '1':
			while end < len(s) and s[end] == '1':
				end += 1
			else:
				length = max(length, end - start)
				start = end + 1
				end += 1
		else:
			start += 1
			end += 1
	else:
		return length


def maxlength(s):
	count = 0
	l = []
	for i in range(len(s)):
		if s[i] == '0':
			l.append(count)
			count = 0
		else:
			count += 1
	l.append(count)
	return max(l)


def maxlength(s):
	maximum_string_count = 0
	cnt = 0
	for i in s:
		if i == '1':
			cnt += 1
			maximum_string_count = max(maximum_string_count, cnt)
		else:
			cnt = 0
	return maximum_string_count


def maxlength(s):
	if s == 0:
		return 0
	else:
		z = s.split('0')
		h = []
		u = 0
		check = 0
		for i in z:
			if i.strip():
				h.append(i)
		final = []
		for i in h:
			u = i.count('1')
			final.append(u)
		if len(final) == 0:
			return 0
		else:
			return sorted(final)[-1]


def maxlength(s):
	x = s.split('0')
	l = 0
	if s == '0':
		return 0
	else:
		for i in x:
			if len(i) > l:
				l = len(i)
	return l


def maxlength(s):
	list = []
	list.append('1')
	maxL = -999
	for i in range(len(s)):
		if list[-1] == s[i]:
			list.append(s[i])
			maxL = max(maxL, len(list) - 1)
		else:
			maxL = max(maxL, len(list) - 1)
			list.clear()
			list.append('1')
	return maxL


def maxlength(s):
	mx = 0
	curr = 0
	for i in range(len(s)):
		if s[i] == '0':
			mx = max(mx, curr)
			curr = 0
		else:
			curr += 1
	return max(mx, curr)


def maxlength(s):
	max_1 = 0
	count = 0
	for i in s:
		if i == '1':
			count += 1
		if i == '0':
			if count > max_1:
				max_1 = count
			count = 0
	return max(max_1, count)


def maxlength(s):
	temp = count = 0
	for elm in s:
		if elm == '1':
			temp += 1
		else:
			if temp > count:
				count = temp
			temp = 0
	if temp > count:
		count = temp
	return count


def maxlength(s):
	i = 0
	max = 0
	temp = 0
	while i < len(s):
		if s[i] == '1':
			temp += 1
		else:
			if max < temp:
				max = temp
			temp = 0
		i += 1
	if max < temp:
		max = temp
	return max


def maxlength(s):
	maxx = 0
	dem = 0
	for i in range(len(s)):
		if s[i] == '1':
			dem += 1
		elif dem > maxx and s[i] != '1':
			maxx = dem
			dem = 0
		else:
			dem = 0
	if dem > maxx:
		return dem
	else:
		return maxx


def maxlength(s):
	m = 0
	curr = 0
	for char in s:
		if char == '1':
			curr += 1
		else:
			curr = 0
		m = max(m, curr)
	m = max(m, curr)
	return m


def maxlength(s):
	n = len(s)
	max2 = 0
	max3 = 0
	flag = False
	for i in range(n):
		if s[i] == '1' and flag == False:
			flag = True
			max2 = max2 + 1
		elif s[i] == '1' and flag == True:
			max2 = max2 + 1
		elif s[i] == '0' and flag == True:
			max3 = max(max2, max3)
			max2 = 0
			flag = False
	return max(max3, max2)


def maxlength(s):
	stack = 0
	max_count = 0
	for i in s:
		if i == '1':
			stack += 1
			max_count = max(stack, max_count)
		else:
			stack = 0
	return max_count


def maxlength(s):
	stack = 0
	sub_seq = []
	for i in s:
		if i == '1':
			stack += 1
		elif stack:
			sub_seq.append(stack)
			stack = 0
		if stack:
			sub_seq.append(stack)
	return max(sub_seq) if sub_seq else 0


def maxlength(s):
	c = 0
	res = 0
	for i in range(len(s)):
		if s[i] == '1':
			c += 1
			res = max(res, c)
		else:
			c = 0
	return res


def maxlength(s):
	if '1' in s:
		s = s.split('0')
		l = []
		for i in s:
			l.append(i.count('1'))
		return max(l)
	else:
		return 0


def maxlength(s):
	i = 0
	res = float('-inf')
	while i < len(s):
		ans = 0
		while i < len(s) and s[i] == '1':
			ans += 1
			i += 1
		res = max(res, ans)
		i += 1
	return res


def maxlength(s):
	s1 = ''
	for i in s:
		if i == '0':
			s1 += ' '
		else:
			s1 += i
	l = s1.split(' ')
	return len(max(l))


def maxlength(s):
	b = s.split('0')
	b = sorted(b, key=len)
	return len(b[-1])


def maxlength(s):
	maxcount = 0
	count = 0
	flagcount = 0
	for i in s:
		if i == '1' and flagcount == 0:
			count = 1
			flagcount = 1
		elif i == '1' and flagcount == 1:
			count += 1
			if count > maxcount:
				maxcount = count
		elif i == '0':
			flagcount = 0
	if count > maxcount:
		maxcount = count
	return maxcount