#C10931. Longest Consecutive Active Days

    ID: 40191 Type: Default 1000ms 256MiB

Longest Consecutive Active Days

Longest Consecutive Active Days

You are given several test cases. For each test case, you are provided with a list of days represented by binary values, where 1 indicates an active day and 0 indicates an inactive day. Your task is to determine the longest sequence of consecutive active days in each test case.

Formally, given an integer \( N \) (the number of days) and an array \( A \) of \( N \) binary integers, you should compute the maximum length of any consecutive subarray consisting only of 1s. For example, if \( A = [1, 1, 0, 1, 1, 1, 0] \), the answer is \( 3 \) since the longest contiguous sequence of 1s has length 3.

The input begins with an integer \( T \) representing the number of test cases, followed by the test cases themselves. Each test case consists of a line containing \( N \) and a subsequent line containing \( N \) space-separated integers.

Good luck!

inputFormat

The input is read from standard input (stdin) and follows the format:

  • The first line contains a single integer ( T ), denoting the number of test cases.
  • For each test case:
    • The first line contains an integer ( N ), the number of days.
    • The second line contains ( N ) space-separated integers where each integer is either 0 or 1.

outputFormat

For each test case, output the longest consecutive sequence of active days on a separate line to standard output (stdout).## sample

3
7
1 1 0 1 1 1 0
5
0 1 1 0 1
4
0 0 0 0
3

2 0

</p>