Problem · Array

Daily Temperatures

Learn this problem
MediumAnduril logoAndurilFULLTIMEONSITE INTERVIEW

Problem statement

Given an array temperatures, return an array answer where answer[i] is the number of days after day i until a strictly warmer temperature occurs. If no later day is warmer, set answer[i] to 0.

Function

dailyTemperatures(temperatures: int[]) → int[]

Examples

Example 1

temperatures = [73,74,75,71,69,72,76,73]return = [1,1,4,2,1,1,0,0]

For example, day 2 with temperature 75 waits four days for temperature 76. No warmer day follows either of the final two reported answers.

Example 2

temperatures = [30,60,90]return = [1,1,0]

Each of the first two days is followed immediately by a warmer day.

Constraints

  • 1 <= temperatures.length <= 100000.
  • -1000 <= temperatures[i] <= 1000.

More Anduril problems

drafts saved locally
public int[] dailyTemperatures(int[] temperatures) {
    // Write your code here.
}
temperatures[73,74,75,71,69,72,76,73]
expected[1,1,4,2,1,1,0,0]
checking account