#C2843. Longest Contiguous Ones
Longest Contiguous Ones
Longest Contiguous Ones
Given a binary array represented as a string, your task is to determine the length of the longest contiguous sequence of 1's for each test case. In other words, for a string S of length \( n \), find the maximum integer \( k \) such that there is a substring consisting of \( k \) consecutive '1's.
For example, if S = '110111', the longest sequence of consecutive 1's is 3.
inputFormat
The input begins with an integer \( T \) on the first line, denoting the number of test cases. Each test case consists of two lines:
- The first line contains an integer \( n \) representing the length of the binary string.
- The second line contains a binary string of length \( n \) (i.e. a string consisting of characters '0' and '1').
outputFormat
For each test case, output a single integer on a new line indicating the length of the longest contiguous sequence of 1's in the given binary string.
## sample3
6
110111
5
00001
4
0000
3
1
0
</p>