Longest subarray
You are given an array A of N integers: A1, A2, ..., AN. You need to
find a longest contiguous subarray in the array such that each integer
in this subarray is an even integer, and output its length.
A contiguous subarray is of the form Aj, A;+1. ..., Aj, for some i and j.
Input
. The first line contains a single integer N denoting the number
of elements in the given array.
. The second line contains N space-separated integers A1, A2
... AN denoting the array A
Output
For each test case, output a single line containing the answer.
Constraints
Example
Input
1224
Output
3
Explanation:
The longest contiguous subarray that has all its elements even will
be the subarray consisting of the 3 elements [2, 2, 4]. Hence, the
answer will be 3.
Sample input >
1 2 2 4
Sample output
3
Program:
n=int(input())
l=list(map(int,input().split()))
m=0
c=0
for i in l:
if i%2==0:
c=c+1
else:
m=max(m,c)
c=0
m=max(m,c)
print(m)
0 Comments