Skip to content

Daily temperatures

MediumPython 3StacksArrays

You are given a list of integers temperatures, where temperatures[i] is the temperature on day i. Return a list answer of the same length where answer[i] is the number of days you have to wait after day i to reach a strictly warmer temperature. If no future day is warmer, answer[i] is 0.

Constraints:
  - 1 <= len(temperatures) <= 10^5
  - 30 <= temperatures[i] <= 100
Examples:
  [73, 74, 75, 71, 69, 72, 76, 73] -> [1, 1, 4, 2, 1, 1, 0, 0]
  [30, 40, 50, 60]                 -> [1, 1, 1, 0]
  [30, 60, 90]                     -> [1, 1, 0]
  [50]                             -> [0]

Python 3, run in your browser. Run tests runs the problem's own tests with a free account; the AI interviewer reads your code and your runs in a practice interview.

Loading the editor…