#K37987. Max Problems in a Row
Max Problems in a Row
Max Problems in a Row
You are given a sequence of N problems, where each problem is assigned a difficulty level. Your task is to determine the maximum number of problems that can be selected consecutively such that no two adjacent problems have the same difficulty. Formally, if the difficulties are given by an array \(d\), you need to choose a contiguous sequence \(d_1, d_2, \ldots, d_k\) where \(d_i \neq d_{i+1}\) for all \(1 \leq i < k\).
For example, for the input sequence [3, 3, 4, 4, 5, 5], the answer is 3 because you can select the subsequence [3, 4, 5] which is the longest contiguous segment satisfying the condition.
Note: If there are no problems (i.e. \(N=0\)), the output should be 0.
inputFormat
The first line contains an integer \(N\) — the number of problems. If \(N > 0\), the second line contains \(N\) space-separated integers representing the difficulty levels of the problems.
outputFormat
Output a single integer — the maximum number of problems that can be selected consecutively such that no two adjacent problems have the same difficulty.
## sample1
1
1