CodePark/ problems / Days Until Warmer
START PRACTICINGPRACTICE
Coding problem · Data structures and algorithms › Stacks

Days Until Warmer

mediumabout 20 minutes in an interview

temps[i] is the temperature on day i. For each day, count how many days you have to wait until a day that is strictly warmer. Return those counts as an array the same length as temps.

  • If no warmer day ever comes, that day's count is 0.
  • A day with the same temperature is not warmer.
  • Temperatures are integers and can be negative.
  • temps can hold up to 100,000 days. If it is empty, return [].
Input: temps = [30, 38, 33, 31, 35, 40] Output: [1, 4, 2, 1, 1, 0]Day 1 (38) waits until day 5 (40): 4 days.
Input: temps = [20, 20, 20] Output: [0, 0, 0]