FrontendX
Next Smaller Element
medium
Description
AI Assistance
Solution
Test Cases
Test Result
Submissions
Canvas
Next Smaller
Element
Find next smaller element using monotonic stack.
Examples
Example 1
Input:
[1,2,3]
Output:
[-1,-1,-1]
Example 2
Input:
[1,2,3]
Output:
[-1,-1,-1]
Hints
Hint 1
Use a monotonic decreasing stack.
Hint 2
For each element, pop until stack top is smaller.
Hint 3
The popped elements have this element as their next smaller.
Next Smaller Element
Find next smaller element using monotonic stack.