DIY: Daily Temperatures
Solve the interview question "Daily Temperatures" in this lesson.
We'll cover the following
Problem statement
You are given an array of integers, temperatures
, which represents the daily temperatures. You have to return an array, days
, such that days[i]
is the number of days you have to wait after the day to get a warmer temperature. If there is no future day for which this is possible, you will keep days[i] == 0
instead.
Note: You can assume that
30 <= temperatures[i] <= 100
.
Input
The input will be an array of integers. The following are examples of input to the function:
// Sample Input 1
temperatures = [68, 71, 78, 67, 66, 69, 79, 68]
// Sample Input 2
temperatures = [30, 50, 98]
// Sample Input 3
temperatures = [30, 48, 36, 40, 45, 50, 38, 66, 90]
Output
The output will also be a list of integers. The following is the expected output for the inputs given above:
// Sample Output 1
[1, 1, 4, 2, 1, 1, 0, 0]
// Sample Output 2
[1, 1, 0]
// Sample Output 3
[1, 4, 1, 1, 1, 2, 1, 1, 0]
Level up your interview prep. Join Educative to access 70+ hands-on prep courses.