Learn
Practice
Newsletter
Resources
Mobile
New
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
132 Pattern
Bookmark
Input
Example 1
Example 2
Example 3
Custom
nums
=
[3, 1, 4, 2]
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
stack
(empty)
find i < j < k with nums[i] < nums[k] < nums[j] (a 1-3-2)
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
stack
(empty)
find i < j < k with nums[i] < nums[k] < nums[j] (a 1-3-2)
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
stack
(empty)
stack =
[ ]
third =
-∞
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
i
stack
(empty)
2
≥ third (-∞)
not a 1 yet
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
i
stack
2
top
push
2
a candidate 3
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
i
stack
2
top
nums[2] =
4
third = -∞
◄ scan
third =
-∞
nums
3
1
4
2
0
1
2
3
i
stack
2
top
4
> top
2
pop as the new 2
◄ scan
third =
2
nums
3
1
4
2
0
1
2
3
i
3
2
stack
(empty)
third =
2
(nums[2] is a bigger 3 to its right)
◄ scan
third =
2
nums
3
1
4
2
0
1
2
3
i
3
2
stack
4
top
push
4
a candidate 3
◄ scan
third =
2
nums
3
1
4
2
0
1
2
3
1
3
2
stack
4
top
1
<
2
<
4
1 < 2 < 3
◄ scan
third =
2
nums
3
1
4
2
0
1
2
3
1
3
2
stack
4
top
return true — pattern found
algo
master
.
io
Step:
Start of algorithm
0 / 12
Input
Example 1
Example 2
Example 3
Custom
nums
=
[3, 1, 4, 2]
0 / 12
algo
master
.
io
Step:
Start of algorithm