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
Find Increasing Triplet SubsequenceInput: [1, 2, 3, 4, 5]12345i=0j=1k=234123Found: 1 < 2 < 3Output: true
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
Asked in
Facebook 42 Google 38 Amazon 31 Microsoft 25
205.4K Views
High Frequency
~15 min Avg. Time
6.4K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen