Skip to main content

Next Greater Element I

Given a list of query values that each appear somewhere in a second, larger array, find the next greater value to the right of each query in that larger array.

Read the full walkthrough →
Visualization step 1 of 8. VISIT.
State
Vvisit
Step 1 / 8
Array Visualization
4
0
1
1
2
2
|
3
1
4
3
5
4
6
2
7
Step 1 / 8
Step 1 of 8. VISIT. Scan the search array (right side) with a decreasing stack to precompute each value's next greater neighbor.
Step Explanation1 / 8
VISIT

Scan the search array (right side) with a decreasing stack to precompute each value's next greater neighbor.

Output0 results
No output yet.