#C2723. Longest Arithmetic Subarray
Longest Arithmetic Subarray
Longest Arithmetic Subarray
Given an array of integers, your task is to determine the length of the longest contiguous subarray that forms an arithmetic progression. An arithmetic progression is a sequence where the difference between consecutive elements is constant. If the array has less than 2 elements, output 0.
Formally, for an array \(a_1, a_2, \ldots, a_n\), a contiguous subarray \(a_l, a_{l+1}, \ldots, a_r\) (with \(r-l+1 \ge 2\)) is arithmetic if there exists a constant \(d\) such that for all \(i\) with \(l+1 \le i \le r\), \(a_i - a_{i-1} = d\). Find the maximum such length in the given array.
inputFormat
The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.
outputFormat
Output a single integer representing the length of the longest arithmetic subarray in the given array.
## sample7
10 7 4 6 8 10 11
4