Implement it on LeetCode. This is the monotonic stack pattern. Use it when you need to find the "next greater" or "next smaller" element for each position. Other problems using this pattern: - Next Greater Element I, II - Largest Rectangle in Histogram - Trapping Rain Water The stack maintains a decreasing (or increasing) order. When a new element breaks the order, you've found the "next greater" for all elements it pops.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/stacks/daily-temperatures-implementation
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████████████████████████████████████████████████████████████████████████████████████████