Given an array of integers temperatures, return an array answer such that answer[i] is the number of days you have to wait for a warmer temperature.
Given an array of integers `temperatures` represents the daily temperatures, return an array `answer` such that `answer[i]` is the number of days you have to wait after the `i-th` day to get a warmer temperature. If there is no future day for which this is possible, keep `answer[i] == 0` instead.
Invariant: The stack strictly maintains temperatures in non-increasing order. Every popped element is matched with its immediate next warmer day in O(1) amortized time.
Each index is pushed at most once and popped at most once, yielding strictly O(N) total runtime.
Bottleneck: Naive comparisons take O(N²). Monotonic stack skips re-checks.
Given an array of integers temperatures, return an array answer such that answer[i] is the number of days you have to wait for a warmer temperature.
Given an array of integers `temperatures` represents the daily temperatures, return an array `answer` such that `answer[i]` is the number of days you have to wait after the `i-th` day to get a warmer temperature. If there is no future day for which this is possible, keep `answer[i] == 0` instead.
Invariant: The stack strictly maintains temperatures in non-increasing order. Every popped element is matched with its immediate next warmer day in O(1) amortized time.
Each index is pushed at most once and popped at most once, yielding strictly O(N) total runtime.
Bottleneck: Naive comparisons take O(N²). Monotonic stack skips re-checks.
Initialized Monotonic Decreasing Stack. Temperatures array ready for single-pass scan.