#C10444. Longest Subarray with Same Value

    ID: 39650 Type: Default 1000ms 256MiB

Longest Subarray with Same Value

Longest Subarray with Same Value

Given an array of integers, find the length of the longest contiguous subarray in which all elements are equal.

You are required to write a program that reads the input from stdin and outputs the result to stdout. The first line of input contains an integer n, the number of elements in the array. The second line contains n space-separated integers. If the array is empty (n=0), the output should be 0.

Example:

For the input:

7
1 1 2 2 2 3 3

the output should be:

3

This corresponds to the longest subarray [2, 2, 2].

The mathematical formulation can be represented in LaTeX as follows: $$\max_{1 \leq i \leq n} \{ k : a_i = a_{i+1} = \cdots = a_{i+k-1} \}.$$

inputFormat

The first line of input contains a single integer n (0 ≤ n ≤ 10^5) representing the number of elements in the array. The second line contains n space-separated integers representing the array elements.

outputFormat

Output a single integer, which is the length of the longest contiguous subarray where all elements are the same. If the array is empty, output 0.## sample

7
1 1 2 2 2 3 3
3