Increasing Triplet Subsequence - Problem
Given an integer array nums, return true if there exists a triple of indices (i, j, k) such that i < j < k and nums[i] < nums[j] < nums[k].
If no such indices exist, return false.
Follow up: Can you implement a solution that runs in O(n) time complexity and O(1) space complexity?
Input & Output
Example 1 — Increasing Sequence
$
Input:
nums = [1,2,3,4,5]
›
Output:
true
💡 Note:
Any triplet (i,j,k) with i < j < k satisfies the condition. For instance, (0,1,2) gives us 1 < 2 < 3.
Example 2 — No Valid Triplet
$
Input:
nums = [5,4,3,2,1]
›
Output:
false
💡 Note:
No triplet satisfies the condition since the array is decreasing.
Example 3 — Mixed Values
$
Input:
nums = [2,1,5,0,4,6]
›
Output:
true
💡 Note:
The triplet (1,4,5) gives indices with values 1 < 4 < 6.
Constraints
- 1 ≤ nums.length ≤ 5 × 105
- -231 ≤ nums[i] ≤ 231 - 1
Visualization
Tap to expand
Understanding the Visualization
1
Input Array
Given integer array with various values
2
Find Pattern
Look for i < j < k where nums[i] < nums[j] < nums[k]
3
Output
Return true if such triplet exists, false otherwise
Key Takeaway
🎯 Key Insight: Use greedy approach to track only the two smallest values seen so far
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code