Question
Largest Alternating Subarray
You are given an array of KaTeX can only parse string typed expression integers. Your task is to find the length of the largest contiguous subarray such that adjacent elements have alternating parity.
A subarray is called alternating if for every pair of adjacent elements:
KaTeX can only parse string typed expression
In other words, even and odd numbers must appear alternately.
Input
The first line contains a single integer KaTeX can only parse string typed expression — the size of the array.
The second line contains KaTeX can only parse string typed expression integers representing the array:
KaTeX can only parse string typed expression.
The second line contains KaTeX can only parse string typed expression integers representing the array:
KaTeX can only parse string typed expression.
Output
Print a single integer — the length of the largest alternating contiguous subarray.
Example
Input
7
1 2 5 8 10 3 4
Output
4
Explanation
The longest alternating subarray is:
KaTeX can only parse string typed expression
Parity sequence:
Odd → Even → Odd → Even
Its length is KaTeX can only parse string typed expression.
7
1 2 5 8 10 3 4
Output
4
Explanation
The longest alternating subarray is:
KaTeX can only parse string typed expression
Parity sequence:
Odd → Even → Odd → Even
Its length is KaTeX can only parse string typed expression.