Question
Largest Same Parity 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 all elements in the subarray have the same parity.
A subarray is called valid if every element is either:
- all even, or
- all odd.
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 contiguous subarray having the same parity.
Example
Input
8
2 4 6 1 3 5 8 1 10
Output
3
Explanation
The longest same parity subarrays are:
KaTeX can only parse string typed expression → all even
KaTeX can only parse string typed expression → all odd
Both have length KaTeX can only parse string typed expression.
8
2 4 6 1 3 5 8 1 10
Output
3
Explanation
The longest same parity subarrays are:
KaTeX can only parse string typed expression → all even
KaTeX can only parse string typed expression → all odd
Both have length KaTeX can only parse string typed expression.