Array / String· 25 min
Increasing Triplet Subsequence
LeetCode #334 · Medium · Interactive step-by-step visualization
Setup
Example input
nums = [2, 1, 5, 0, 4, 6]Step 1 / 13
Current step
1 / 13Initialize two thresholds. They represent the smallest first and second values seen. Both begin at infinity.
Step log
nums
2
01
15
20
34
46
5first
∞
second
∞
Active cursor
Comparing
Best or completed
Leaving or removed
increasing-triplet-subsequence.java
1public boolean increasingTriplet(int[] nums) {2 int first = Integer.MAX_VALUE;3 int second = Integer.MAX_VALUE;4 for (int value : nums) {5 if (value <= first) first = value;6 else if (value <= second) second = value;7 else return true;8 }9 return false;10}● Java
Time
O(n)
Space
O(1)
Pattern
array scan
Frames
13
