The algorithm: Create an empty stack (will store indices) For each day : - While stack is not empty AND current temp > temp at stack.top(): - Pop the index. The answer for that index is - popped_index. - Push current index onto stack Indices left in the stack have no warmer day (answer remains ) This is a monotonic decreasing stack: temperatures decrease from bottom to top.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
$ curl repovive.com/roadmaps/maang-interview-prep/stacks/daily-temperatures-solution
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████████████████████████████████████████████████████████████████████████████████