FastPrepDaily Temperatures

Daily Temperatures

Amazon logoAmazon● MediumINTERNONSITE INTERVIEW
Learn

Problem statement

Given an array of daily temperatures, return an array where each position contains the number of days until a strictly warmer temperature occurs. If no warmer future day exists, place 0 at that position.

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 temperature 75, the next warmer reading is 76 four days later.

Example 2

temperatures = [30,40,50,60]return = [1,1,1,0]

Every day except the last is followed immediately by a warmer day.

Constraints

  • 1 <= temperatures.length <= 10^5
  • -10^4 <= temperatures[i] <= 10^4

More Amazon problems

See Amazon hiring insights
public int[] dailyTemperatures(int[] temperatures) {
    // Write your solution here.
}
temperatures[73,74,75,71,69,72,76,73]
expected[1,1,4,2,1,1,0,0]
Checking account…