Skip to main content

Daily Temperature Wait Counter

medium
StackArrayMonotonic Stack
Asked atAmazonGoogleUberMicrosoft

Problem Description

You are given an array `readings` of daily temperature readings. For each day, determine how many days you have to wait until a warmer temperature occurs. If no future day has a warmer temperature, the answer for that day is `0`.

Return an array `result` where `result[i]` is the number of days after day `i` until a warmer reading is recorded.

**Example 1:**
```
Input: readings = [62, 58, 65, 70, 60, 72, 68, 75]
Output: [2, 1, 1, 2, 1, 2, 1, 0]
```

**Example 2:**
```
Input: readings = [90, 85, 80, 75]
Output: [0, 0, 0, 0]
```

Constraints

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

Follow-up

Can you solve this problem in O(1) extra space (not counting the output array)?

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.

CodeBrainery

A technical blogging platform for developers and engineers to share knowledge and connect.

Connect

© 2026 Kodetra Technologies Pvt. Ltd. All rights reserved. CodeBrainery is a product of Kodetra Technologies Pvt. Ltd.