Given an array temperatures of daily temperatures, return an array answer such that answer[i] is the number of days you must wait after the i-th day to get a warmer temperature. If there is no such day, set answer[i] = 0.
1 ≤ temperatures.length ≤ 10⁵30 ≤ temperatures[i] ≤ 100Keep a stack of INDICES whose warmer day is still unknown, with temperatures decreasing down the stack.
For each day you want the first later day that is strictly warmer. The direct way is to look ahead from every day until you find one. That is fine when warm days come often, and terrible when they don't: on a long run of equal temperatures, every day looks all the way to the end and finds nothing.
Time O(n)Space O(n)
The full walkthrough and code are part of Premium