Grokking the Coding Interview: Patterns for Coding Questions
0% completed
Solution: Daily Temperatures
Problem Statement
Given an array of integers temperatures representing daily temperatures, calculate how many days you have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead.
Examples
Example 1
- Input:
temperatures = [70, 73, 75, 71, 69, 72, 76, 73] - Output:
[1, 1, 4, 2, 1, 1, 0, 0] - Explanation: The first day's temperature is 70 and the next day's temperature is 73 which is warmer. So for the first day, you only have to wait for 1 day to get a warmer temperature
.....
.....
.....
Like the course? Get enrolled and start learning!
S
saurabh28jaiswal
· 2 years ago
it seems we are calculating difference of 2 pointers in array, so can I use 2 pointer mechanism? however array is not sorted?
Show 1 reply