โ† Adobe questions

Next rise in temperature days

Filed under Adobe

Free read 1 of 3

For each element, iterate forward until a larger value is found.

The question

Given an array of integers representing daily temperatures, return an array where the i-th element is the number of days you have to wait after the i-th day to get a warmer temperature. If no future day is warmer, return 0.

Constraints

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

Examples

Input
[73, 74, 75, 71, 69, 72, 76, 73]
Output
[1, 1, 4, 2, 1, 1, 0, 0]
Why
For 73, next warmer is 74 (1 day). For 75, next warmer is 76 (4 days).

Approach

  1. For each element, iterate forward until a larger value is found.

Solution

O(n) time, O(n) space

Python
def dailyTemperatures(T):
    res, stack = [0]*len(T), []
    for i, t in enumerate(T):
        while stack and T[stack[-1]] < t:
            idx = stack.pop()
            res[idx] = i - idx
        stack.append(i)
    return res

Tips

  • What they are testing: Check arrays with strictly decreasing temperatures.
  • Common mistake: Using a nested loop approach (O(n^2)), which will time out on large inputs.

Related Adobe questions

Collected from public candidate posts and coding forums. Updated Nov 2026.