Determine whether an array contains an increasing subsequence of length 3.
Given an integer array nums, determine whether there exists a subsequence of length 3 such that the three values are strictly increasing.
A subsequence does not need to be contiguous; you may delete any number of elements without changing the order of the remaining elements.
Return true if there exists indices i < j < k with nums[i] < nums[j] < nums[k], otherwise return false.
Input Format
- A single integer array
nums.
Output Format
- Return a boolean value indicating whether an increasing triplet subsequence exists.
Constraints
1 <= nums.length- Elements are integers.
- The exact official limits are unknown from the provided metadata; the intended solution should work in linear time and constant extra space.
Example 1
Input
nums = [1, 2, 3, 4, 5]
Output
true
Explanation
The subsequence [1, 2, 3] is strictly increasing.
Example 2
Input
nums = [5, 4, 3, 2, 1]
Output
false
Explanation
No increasing subsequence of length 3 exists.
Show 1 more example
Example 3
Input
nums = [2, 1, 5, 0, 4, 6]
Output
true
Explanation
One valid subsequence is [1, 4, 6].
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.