#T406. 最长平台

最长平台

Description

Given an array that has already been sorted in ascending order, a plateau in this array is defined as a consecutive sequence of elements with the same value that cannot be extended further.
For example, in the array 1, 2, 2, 3, 3, 3, 4, 5, 5, 6, the plateaus are 1, 2-2, 3-3-3, 4, 5-5, and 6. Write a program that takes an array as input and finds the longest plateau in it. In the example above, 3-3-3 is the longest plateau.

Input Format

The first line contains an integer n, representing the number of elements in the array.
The second line contains n integers separated by a single space.

Output Format

Output the length of the longest plateau.

n = int(input())
arr = list(map(int, input().split()))
max_length = 1
current_length = 1

for i in range(1, n):
    if arr[i] == arr[i - 1]:
        current_length += 1
        if current_length > max_length:
            max_length = current_length
    else:
        current_length = 1

print(max_length)
10
1 2 2 3 3 3 4 5 5 6
3
## Source

CodesOnline