0% completed
Daily Temperatures (medium)
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
.....
.....
.....
Anand Mohan
· 3 years ago
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?
SHLOK KOTHARI
· 2 years ago
I ask this question to ensure I understand the solution correctly. In a scenario where array elements are in a descending order and the max is placed at the last position, we will be required to travel the array twice. The number of times we process each entry is twice. Does this mean the time complexity is 2N?
I understand that big O would be O(n), however would like to ensure I am thinking right.