#C5447. Longest Contiguous Subarray with Equal Elements
Longest Contiguous Subarray with Equal Elements
Longest Contiguous Subarray with Equal Elements
You are given an array \(A\) of \(n\) integers. Your task is to determine the length of the longest contiguous subarray in which every element is identical.
If \(n=0\), the answer is defined to be \(0\). Otherwise, you need to find the maximum count of consecutive occurrences of any number in the array.
For example, consider the array: [1, 2, 2, 3, 3, 3, 1]. The longest contiguous segment of equal numbers is [3, 3, 3] and its length is 3.
Formally, if we denote a contiguous subarray starting at index \(i\) and ending at index \(j\) (where \(0 \leq i \leq j < n\)) having all equal elements, then the answer is
[ \max_{0 \leq i \leq n-1} { j-i+1 \mid A_i = A_{i+1} = \dots = A_j } ]
inputFormat
The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers representing the elements of the array. If \(n = 0\), then the second line may be empty.
outputFormat
Output a single integer representing the length of the longest contiguous subarray with all elements equal.
## sample4
1 1 1 1
4