#K50012. Arithmetic Subsequence Finder
Arithmetic Subsequence Finder
Arithmetic Subsequence Finder
You are given an array of integers. Your task is to determine whether there exists any arithmetic subsequence of length 3 within the array. An arithmetic subsequence is defined as a sequence of three indices i, j, k (with i < j < k) for which the condition \(a[j]-a[i]=a[k]-a[j]\) holds.
For example, consider the array [1, 2, 3, 4, 5]. Here, the subsequence (1, 2, 3) forms an arithmetic sequence since \(2-1=3-2\). If such a subsequence exists, output YES
; otherwise, output NO
.
The input will consist of multiple test cases. For each test case, check if the given array contains an arithmetic subsequence of length 3 and print the corresponding result.
inputFormat
The first line of input contains an integer T
denoting the number of test cases. The description of T
test cases follows.
For each test case:
- The first line contains an integer
N
representing the number of elements in the array. - The second line contains
N
space-separated integers, which represent the elements of the array.
outputFormat
For each test case, output a single line containing either YES
if there exists an arithmetic subsequence of length 3, or NO
otherwise.
2
5
1 2 3 4 5
4
1 3 7 10
YES
NO
</p>