‹ DS&A interview · Socratic
DSA · Monotonic stack · #14

Daily Temperatures

Module 17 · difficulty 3/5·30:00starts on first keystroke

Given an array `temperatures` of daily temperatures, return an array `answer` such that `answer[i]` is the number of days you have to wait after day `i` to get a warmer temperature. If there is no future day for which this is possible, `answer[i] == 0`.

Examples
  • temperatures = [73,74,75,71,69,72,76,73] [1,1,4,2,1,1,0,0]
  • temperatures = [30,40,50,60] [1,1,1,0]
  • temperatures = [30,60,90] [1,1,0]
Constraints
  • · 1 <= temperatures.length <= 10^5
  • · 30 <= temperatures[i] <= 100
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.