#C2451. Longest Run in a Deck of Cards
Longest Run in a Deck of Cards
Longest Run in a Deck of Cards
Given a deck of cards represented by a sequence of integers, your task is to determine the length of the longest run in the deck. A run is defined as a sequence of at least two consecutive cards where the difference between adjacent cards is constant. In other words, if the deck is given as an array (a_1, a_2, \dots, a_n), a run is a subarray (a_i, a_{i+1}, \dots, a_j) (with (j-i+1 \ge 2)) such that for all (k) with (i \le k < j) we have: [ a_{k+1} - a_k = d ] for some constant (d). If the deck contains only one card, output (0).
inputFormat
The input is read from standard input. The first line contains an integer (n) (the number of cards). The second line contains (n) space-separated integers that represent the values on the cards.
outputFormat
Output a single integer to standard output, which is the length of the longest run in the deck.## sample
6
1 2 3 5 6 8
3