RAVI1234 - Editorial

PROBLEM LINK:

Practice | Contest
Author: Kapil Bansal
Tester: Kapil Bansal
Editorialist: Kapil Bansal

DIFFICULTY:

EASY

PROBLEM:

Ravi is planning to plant a bomb in the city. City is organised in such a way that only similar continuous blocks gets affected by such attacks. Ravi have the information of the arrangement of blocks. Help him to calculate maximum number of blocks that can be destroyed.

EXPLANATION:

The basic idea is to calculate the length of maximum contiguos 0’s or 1’s. Therefore, we can divide the whole array of contiguos blocks into multiple arrays and then finding the array with max length.

SOLUTION:

n=int(input())
s=''.join(input().split())
l1=[x for x in s.strip('0').split('0')]
_max=len(l1[-1])
l2=[x for x in s.strip('1').split('1')]
if _max<len(l2[-1]):
    _max=len(l2[-1])
print(_max)