A digital machine generates binary data which consists of a string of 0s and 1s. A maximum signal M, in the data, consists of the maximum number of either 1s or 0s appearing consecutively in the data but M can’t be at the beginning or end of the string. Design a way to find the length of the maximum signal.
Input
The first line of the input consists of an integer N, representing the length of the binary string. The second line consists of a string of length N consisting of 0s and 1s only.
Output
Print an integer representing the length of the maximum signal.
Example
Example 1:
Input
6
101000
Output
1
Explanation
For 101000, M can be 0 at the second index or at the third index so in both cases max length = 1.
Example2:
Input
9
101111110
Output
6
Explanation
For 101111110, M = 111111 so maxlength = 6.
Solution
Input
5
10110
Program :
n=int(input())
no=input()
list1=list(no)
k=list1[0]
list1.pop(0)
count=1
for i in range(0,n):
if k==list1[i]:
list1.pop(i)
count+=1
else:
break
l=list1[n-count-1]
for i in range(n-count-1,-1,-1):
if l==list1[i]:
list1.pop(i)
else:
break
max1=0
store=0
m=list1[0]
for i in range(0,len(list1)):
if m==list1[i]:
max1+=1
else:
m=list1[i]
if max1>store:
store=max1
max1=1
if max1>store:
store=max1
print(store)
a=input()
ReplyDeleteb=input()
c=list(b)
c.sort()
for i in range(1,len(c)):
res=(c.count('1'))-1
print(res)
Post a Comment