#K90577. Longest Consecutive Segment

    ID: 37783 Type: Default 1000ms 256MiB

Longest Consecutive Segment

Longest Consecutive Segment

Given an array of integers, find the starting index and the length of the longest contiguous segment consisting of identical numbers. In case multiple segments have the same length, return the one that appears first. If the input list is empty, output (-1\ 0).

The problem is solved by scanning the array once while tracking the length and starting index of the current segment and updating the maximum when necessary. Handle edge cases like an empty array or an array of one element.

inputFormat

The input is read from stdin. The first line contains an integer (n), denoting the number of elements in the array. The second line contains (n) space-separated integers. If (n = 0), the array is considered empty.

outputFormat

Print to stdout two space-separated integers: the starting index (0-indexed) of the longest contiguous segment of identical numbers, and the length of that segment.## sample

11
1 1 2 2 2 3 3 3 3 2 2
5 4