#C13662. Longest Contiguous Subarray of Identical Elements

    ID: 43225 Type: Default 1000ms 256MiB

Longest Contiguous Subarray of Identical Elements

Longest Contiguous Subarray of Identical Elements

Given an array of integers, your task is to find the longest contiguous subarray in which all the elements are identical. You need to output the length of that subarray along with the repeated element’s value. If the input list is empty, output 0 None.

For example, consider the array [1, 2, 2, 3, 3, 3, 2, 2, 2, 2, 1, 1]. The longest contiguous subarray is [2, 2, 2, 2], so the output should be 4 2.

The problem can be solved in linear time, i.e. in \(O(n)\) time, by traversing the array once and keeping track of the current streak.

inputFormat

The input is read from standard input (stdin) and consists of two parts:

  • The first line contains an integer \(n\) representing the number of elements in the list.
  • The second line contains \(n\) space-separated integers. If \(n = 0\), then the second line will be empty.

outputFormat

Print two space-separated values to standard output (stdout): the length of the longest contiguous subarray and the value of the element in that subarray. If the list is empty, output 0 None.

## sample
12
1 2 2 3 3 3 2 2 2 2 1 1
4 2

</p>