ntree.ai

Daily Temperatures

mediumArraysStack

Given an array of temperatures, where each entry is a day's temperature, return an array answer where answer[i] is the number of days you must wait after day i for a warmer day.

If no warmer day ever comes, put 0.

Example 1:

Input:  temperatures = [73, 74, 75, 71, 69, 72, 76, 73]
Output: [1, 1, 4, 2, 1, 1, 0, 0]
Explanation: day 2 is 75, and the next warmer day is day 6 at 76 which is four days later.

Constraints:

  • 1 <= len(temperatures) <= 10^5
  • -100 <= temperatures[i] <= 100