Design Gurus Logo
Daily Temperatures (medium)

Problem Statement

You are given a list of daily temperatures. Your task is to return an answer array such that answer[i] is the number of days you would have to wait until a warmer temperature for each of the days. If there is no future day for which this is possible, put 0 instead.

Examples

    • Input: [45, 50, 40, 60, 55]
    • Expected Output: [1, 2, 1, 0, 0]
    • Justification: The next day after the first day is warmer (50 > 45). Two days after the second day, the temperature is warmer (60 > 50).. The next day after the third day is warmer (60 > 40). There are no warmer days after the fourth and fifth days.
    • Input: [80, 75, 85, 90, 60]
    • Expected Output: [2, 1, 1, 0, 0]
    • Justification: Two days after the first day, the temperature is warmer (85 > 80). The next day after the second day is warmer (85 > 75). The next day after the third day is warmer (90 > 85). There are no warmer days after the fourth and fifth days.
    • Input: [32, 32, 32, 32, 32]
    • Expected Output: [0, 0, 0, 0, 0]
    • Justification: All the temperatures are the same, so there are no warmer days ahead.

Constraints:

  • 1 <= temperatures.length <= 10<sup>5</sup>
  • 30 <= temperatures[i] <= 100

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory