#K4006. Find an Increasing Triplet Subsequence

    ID: 26558 Type: Default 1000ms 256MiB

Find an Increasing Triplet Subsequence

Find an Increasing Triplet Subsequence

You are given an array of n integers A. Your task is to determine whether there exist indices i, j, and k (with i < j < k) such that

$$A_i < A_j < A_k$$

If such a triplet exists, print YES, otherwise print NO.

Example:

  • For A = [1, 2, 3, 4, 5], the answer is YES because 1, 2, 3 form a valid triplet.
  • For A = [5, 4, 3, 2], no such triplet exists and the answer is NO.

inputFormat

The first line of input contains an integer T (the number of test cases).

For each test case, the first line contains an integer n (the length of the array). The next line contains n space-separated integers representing the array A.

It is guaranteed that T > 0 and each array has at least 1 element.

outputFormat

For each test case, output a single line containing YES if there exists a triplet i, j, k (with i < j < k) satisfying $$A_i < A_j < A_k$$; otherwise, print NO.

## sample
3
5
1 2 3 4 5
4
5 4 3 2
6
1 2 6 4 5 3
YES

NO YES

</p>