#K57242. Longest Contiguous Subarray

    ID: 30377 Type: Default 1000ms 256MiB

Longest Contiguous Subarray

Longest Contiguous Subarray

You are given an array of integers. Your task is to determine the length of the longest contiguous subarray in which all elements are the same.

In other words, find the maximum number of consecutive identical elements. For example, given the array [1, 2, 2, 3, 3, 3, 2, 2], the answer is 3 because the longest contiguous subarray with identical numbers is [3, 3, 3].

Note: If the array is empty, the result should be 0.

The mathematical formulation: Given an array \( a_1, a_2, \dots, a_n \), find \[ \max_{1 \leq i \leq n} \{ \text{length of contiguous segment starting at } i \text{ with } a_i=a_{i+1}=\cdots \} \]. \]

inputFormat

The input is read from stdin and consists of:

  1. A single integer \( n \) (\( n \geq 0 \)) that denotes the number of elements in the array.
  2. If \( n > 0 \), the next line contains \( n \) space-separated integers representing the array elements.

outputFormat

Output to stdout a single integer which is the length of the longest contiguous subarray with all elements equal.

## sample
8
1 2 2 3 3 3 2 2
3