A factory's automated safety system produces one audit entry for each of n consecutive days. Each entry is 1 if every safety check passed that day, or 0 if at least one check failed. Given the full log in chronological order, find the length of the longest streak of consecutive days that all show a passing (1) result.
The first line contains a single integer n (1 <= n <= 100000) -- the number of days in the log. The second line contains n space-separated integers, each either 0 or 1 -- the log entries in chronological order.
Print a single integer: the length of the longest streak of consecutive 1s in the log (print 0 if the log contains no passing day at all).
Example 1
Input
8 1 1 0 1 1 1 0 1
Expected
3
Explanation
The log has passing-day runs of length 2 (the first two days), 3 (days four through six), and 1 (the last day); the longest of these is 3.
Example 2
Input
5 0 0 0 0 0
Expected
0
Explanation
Every single day failed at least one check, so there is no passing streak at all and the answer is 0.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →