PIXELBANKv9.1.0
Menu

Daily Temperatures

Given an array of daily temperatures, return an array where each element tells you how many days you have to wait until a warmer temperature. If no future day is warmer, put 0.

Output as space-separated integers.

Example:

Input:
73,74,75,71,69,72,76,73
Output:
1 1 4 2 1 1 0 0
Reasoning:
  • We start by iterating over the input array from left to right, comparing each temperature with the subsequent ones to find a warmer temperature.
  • For the first element 7373, we find a warmer temperature 7474 on the next day, so the output is 11.
  • We repeat this process for each element: 7474 is followed by 7575, which is warmer, so the output is 11; 7575 is followed by temperatures that are not warmer until 7676, which is 44 days later, so the output is 44.
  • The rest of the elements are processed similarly, resulting in the output array: 114211001 1 4 2 1 1 0 0

Constraints:

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

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Daily Temperatures - Medium | PixelBank