#K4126. Longest Contiguous Arithmetic Subsequence
Longest Contiguous Arithmetic Subsequence
Longest Contiguous Arithmetic Subsequence
Given a list of integers, your task is to find the length of the longest contiguous subsequence where the difference between consecutive elements is constant. In other words, you need to find the longest contiguous arithmetic subarray.
An arithmetic sequence is one in which the difference \(d = a_{i+1} - a_i\) is the same for all valid indices \(i\). The input begins with an integer \(n\) (the size of the list) followed by \(n\) integers, and the output should be the length of the longest contiguous arithmetic subsequence present in the list.
Note: All formulas should be presented in LaTeX. For example, use \(d = a_{i+1} - a_i\) for the common difference.
inputFormat
The first line of input contains an integer n denoting the number of elements in the list. The second line contains n space-separated integers.
outputFormat
Print a single integer representing the length of the longest contiguous arithmetic subsequence.
## sample7
3 6 9 12 15 18 21
7
</p>