All problems

Problem 303

Max Consecutive Ones

Easy · 10 pts · Array

Problem

You are given a binary array, that is, an array in which every element is either 0 or 1. Find the length of the longest block of consecutive 1s. A block must be contiguous: a single 0 between two groups of 1s ends one block and starts another. If the array contains no 1 at all, the answer is 0.

Input

The first line contains an integer N, the size of the array. The second line contains N space-separated integers A[0], A[1], ..., A[N-1]. Every value is 0 or 1.

Output

Print the length of the longest run of consecutive 1s.

Constraints

1 <= N <= 100000; A[i] is 0 or 1

Example input

6
1 1 0 1 1 1

Example output

3

Explanation

The array 1 1 0 1 1 1 has a run of two 1s and then, after the 0, a run of three 1s. The longer run has length 3.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Alternate Positive and Negative Next: Max Consecutive Ones with K Flips