Answer: Google OA Question 2024 February | Monotonic Stack | on-campus
Answer · Posted Jun 2026
Solution : Daily Temperatures — Monotonic Stack Approach A naive approach of checking future days for each index takes O(N2) time, which is too slow. We can solve this in linear time O(N) using a Monotonic Stack. The stack keeps track of indices of days that we haven't found a warmer temperature for yet. Since we want to find the next warmer day, we keep the stack in monotonically decreasing order of temperatures. As we iterate through the array, if ...
The full answer & interview discussion are available to premium members.
Log in Create a free account