Days Until a Warmer Day
Updated
Problem statement
You are given an integer array temperatures, where temperatures[i] is the temperature on day i.
For each day, find how many days you have to wait after it until a day that is strictly warmer. Return an array answer of the same length, where answer[i] is that number of days.
- A later day with the same temperature does not count as warmer.
- If no later day is warmer than day
i, thenanswer[i]is0.
Function
daysUntilWarmer(temperatures: int[]) → int[]Examples
Example 1
temperatures = [3,5,4,4,7,2]return = [1,3,2,1,0,0]Day 0 (3) is followed by 5 on day 1, so it waits 1 day. Day 1 (5) waits until 7 on day 4, which is 3 days. Day 2 (4) also waits for day 4, 2 days later: day 3 has the same temperature 4, which is not warmer. Day 3 waits 1 day. No later day is warmer than day 4 (7) or day 5 (2), so both get 0.
Example 2
temperatures = [10,10,10]return = [0,0,0]Every day has the same temperature. A day with an equal temperature is not warmer, so every answer is 0.
Example 3
temperatures = [-5,-8,-2,0]return = [2,1,1,0]Temperatures can be below zero. Day 0 (-5) and day 1 (-8) both wait for -2 on day 2, which is 2 days and 1 day away. Day 2 waits 1 day for 0. The last day gets 0.
Constraints
1 <= temperatures.length <= 2000-100 <= temperatures[i] <= 100
More C3.ai interview questions
- Fewest Turns to Open a Wheel LockPHONE SCREEN · Seen Nov 2024
- Longest Run of Ones After Flipping k ZerosPHONE SCREEN · Seen Mar 2022
- Top K Frequent ElementsPHONE SCREEN · Seen Feb 2021
- Item Prices From Material CostsPHONE SCREEN · Seen Dec 2020
- Adjacent-Key Lock PatternsPHONE SCREEN · Seen Feb 2014
- Drop Recent Duplicate MessagesOA · Seen Oct 2026
- Maximum K-Star SumOA · Seen Oct 2026
- Every Result of Grouping an ExpressionONSITE INTERVIEW · Seen Jan 2023
- Fewest Jumps to the Last IndexONSITE INTERVIEW · Seen Jan 2023
- Rotate a Square Grid ClockwiseONSITE INTERVIEW · Seen Jan 2023
Similar questions at other companies
- Asteroid CollisionSiemens · PHONE SCREEN
- Billing Log with Undo and RedoReddit · PHONE SCREENReddit interview questions
- Compress Editor Actions into Operational Transform OperationsReplit · OA · PHONE SCREEN · ONSITE INTERVIEW
- Daily TemperaturesCARS24 · PHONE SCREEN
- Flatten a Mixed JSON ListNike, Inc. · ONSITE INTERVIEWNike, Inc. interview questions
- Next Greater Indices and Maximum GapTikTok · PHONE SCREENTikTok interview questions
- Fountain SafetyGoogle · ONSITE INTERVIEWGoogle interview questions
- Trace Events from Stable Whole-Stack StatesAnthropic · ONSITE INTERVIEWAnthropic interview questions
- Next Smaller Ticket PriceAmazon · ONSITE INTERVIEW
- Next Greater Value in a Circular ArrayPayPay · PHONE SCREENPayPay interview questions