#K3886. Longest Arithmetic Subarray
Longest Arithmetic Subarray
Longest Arithmetic Subarray
Given a sequence of n integers, your task is to determine the length of the longest contiguous subarray that forms an arithmetic progression. An arithmetic progression is a sequence in which the difference between consecutive elements is constant, i.e., for any valid index i the condition \(a_{i+1} - a_i = d\) holds for some constant \(d\). For example, in the sequence [10, 7, 4, 6, 8], the longest arithmetic subarray is [10, 7, 4] with a common difference of -3.
The input is provided as two lines. The first line contains the integer n, and the second line contains n integers separated by spaces. Your program should output the length of the longest arithmetic subarray.
inputFormat
The input consists of two lines:
- The first line contains an integer n (1 ≤ n ≤ 105), the number of elements in the sequence.
- The second line contains n space-separated integers representing the sequence. Each integer can be any valid integer.
outputFormat
Output a single integer representing the length of the longest contiguous arithmetic subarray in the given sequence.
## sample5
10 7 4 6 8
3
</p>