The Opposite Rule
This is identical to Next Greater Element, but instead of popping elements that are `<= nums[i]`, we pop elements that are `>= nums[i]`.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Given an array, find the first strictly smaller element to the right of each element. This uses a Monotonic Increasing Stack.
This is identical to Next Greater Element, but instead of popping elements that are `<= nums[i]`, we pop elements that are `>= nums[i]`.
Because we pop all larger elements before pushing the current element, the stack naturally maintains a strict increasing order from bottom to top.
Next Smaller Element is a critical subroutine used to solve much harder problems like "Largest Rectangle in Histogram" and "Maximal Rectangle".