Skip to main content

Next Greater Temperature Awaiter

easy
StackArrayMonotonic StackMonotonic Stack
Asked atAmazonGoogleMicrosoftBloombergUber

Problem Description

You are given an array `readings` of integers, where each element represents a temperature recorded on a given day.

For each day, find how many days you would have to wait until a strictly warmer temperature occurs. If no warmer day exists in the future, the answer for that day is `0`.

Return an integer array `result` of the same length, where `result[i]` is the number of days to wait from day `i` for a warmer reading.

**Example 1:**
```
Input: readings = [65, 72, 60, 68, 75, 61, 70]
Output: [1, 3, 1, 1, 0, 1, 0]
```

**Example 2:**
```
Input: readings = [30, 30, 30]
Output: [0, 0, 0]
```

Constraints

  • 1 <= readings.length <= 10^5
  • 1 <= readings[i] <= 120

Follow-up

Can you solve this using O(1) extra space beyond the output array by working backwards?

Hints

Try the problem first. If you get stuck, you can reveal hints one at a time.

Solution

Leaderboard

No entries yet for python.

Be the first — submit an accepted solution.