Largest Substring

3.7

25 votes
Algorithms, Binary Search, Easy, Hash Maps, Implementation, Searching, String Manipulation
Problem

You are given a string S of length N. Each character of the string is either 0 or 1. Now, you need to select the largest substring in which the count of 0 in the string is more than the count of 1. Print the maximum possible length of the subarray in the output.

Input

The first line contains an integer N as input. 
The next line contains a string comprising of 0 and 1. The length of this string is exactly N.

Output

In the output print the length of the largest substring in which the count of 0 is more than 1.

Constraints

1N105

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

The last three characters i.e. 100 forms a substring of length 3 which is the largest substring possible in which 0 are more than 1.

Editor Image

?