#K95107. Increasing Triplet Subsequence
Increasing Triplet Subsequence
Increasing Triplet Subsequence
You are given an array of integers. Your task is to determine whether there exists a strictly increasing triplet in the array. More formally, you need to check if there exist indices \( i, j, k \) with \( i < j < k \) such that:
\( nums[i] < nums[j] < nums[k] \)
If such a triplet exists, output True
; otherwise, output False
.
Example
- For the input array
[1, 2, 3, 4, 5]
, the output should beTrue
because \(1 < 2 < 3\) (among many other triplets) is a valid increasing triplet. - For the input array
[5, 4, 3, 2, 1]
, the output should beFalse
.
inputFormat
The first line contains an integer \( n \) representing the number of elements in the array. The second line contains \( n \) space-separated integers representing the elements of the array.
outputFormat
Output a single line containing either True
or False
depending on whether there exists an increasing triplet subsequence.
5
1 2 3 4 5
True