Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Next Greater Node In Linked List
Bookmark
Brute Force
Monotonic Stack
Input
Input 1
Input 2
Input 3
Custom
values
=
[2, 1, 5]
head
null
2
0
1
1
5
2
ans
head
null
2
0
1
1
5
2
ans
head
null
2
0
1
1
5
2
ans
head
null
2
0
1
1
5
2
i
ans
node
2
: walk forward for the first greater value
head
null
2
0
1
1
5
2
j
i
ans
1
<= 2 → keep walking
head
next greater
null
2
0
1
1
5
2
j
i
ans
5
5
> 2 → result[0] = 5
head
null
2
0
1
1
5
2
i
ans
5
node
1
: walk forward for the first greater value
head
next greater
null
2
0
1
1
5
2
j
i
ans
5
5
5
> 1 → result[1] = 5
head
null
2
0
1
1
5
2
i
ans
5
5
node
5
: walk forward for the first greater value
head
null
2
0
1
1
5
2
i
ans
5
5
0
reached null with nothing bigger →
0
head
null
2
0
1
1
5
2
ans
5
5
0
answer =
[5, 5, 0]
algo
master
.
io
Step:
Brute force: for each node, walk forward for the first greater value.
0 / 9
Input
Input 1
Input 2
Input 3
Custom
values
=
[2, 1, 5]
0 / 9
algo
master
.
io
Step:
Brute force: for each node, walk forward for the first greater value.