Problems > Alternating Parity Stretch

Alternating Parity Stretch

Difficulty: 1100 3000 ms 128 MB

implementation

Find the longest contiguous stretch where the values alternate between even and odd at every step.

Input: the first line has N; the second line has N integers.

Output: the maximum length of an alternating-parity stretch.

Constraints:

  • 1 ≤ N ≤ 105
  • −109 ≤ ai ≤ 109

Sample Tests

Input 1
6
2 1 4 7 6 6
Output 1
5
Input 2
1
3
Output 2
1

Read the Editorial

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.