FastPrepDaily Temperatures

Daily Temperatures

CARS24 logoCARS24● MediumFULLTIMEPHONE SCREEN

Problem statement

For each day in temperatures, return the number of days until the first later day with a strictly warmer temperature. Return 0 for a day that has no warmer later day.

Return one value per input day, in the same order.

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]

The first two waits are one day. Day 2 waits four days for 76; days 3, 4, and 5 wait 2, 1, and 1 days. The last two days have no warmer successor.

Example 2

temperatures = [30,30,31]return = [2,1,0]

Equal temperatures are not warmer. The first day waits two days and the second waits one.

Constraints

  • 1 <= temperatures.length <= 100000.
  • 30 <= temperatures[i] <= 100.

More CARS24 problems

See CARS24 hiring insights
Saved
public int[] dailyTemperatures(int[] temperatures) {
    // Write your code here.
}
Checking account…