Daily Temperatures

Medium

Daily Temperatures

Problem Statement

You are given a list of daily temperatures

temperatures
, representing the temperature of each day in a sequence. For each day, you want to know the number of days before it will have a higher temperature.

Task

Write a function to return the number of days before each day will have a higher temperature. The result should be an array where

result[i]
stores the number of days before
temperatures[i]
will have a higher temperature.

Rules and Constraints

  • temperatures
    is an array of integers representing the temperature of each day in a sequence.
  • The temperature of each day is represented as an integer in the range
    [32, 123]
    .
  • The result array should be the same length as
    temperatures
    .
  • Time complexity: The function should run in O(n) time complexity where n is the length of the
    temperatures
    array.
  • Space complexity: The function should run in O(n) space complexity where n is the length of the
    temperatures
    array.

Example

Input: {"temperatures":[73,74,75,71,69,72,76,73]} Output: [1,1,4,2,1,1,0,0]

CompaniesAmazon
JavaScript

Login to write code

Solve problems, verify your skills, and earn XP.