Algorithms Playbook
← All problems
MediumMonotonic stack →Similar to: Daily Temperatures

How long until it warms up?

Problem

Given an array t of daily temperatures, return an array ans where ans[i] is the number of days after day i until a warmer temperature. If there is none, ans[i] = 0.

Examples

Input: t = [73, 74, 75, 71, 69, 72, 76, 73]

Output: [1, 1, 4, 2, 1, 1, 0, 0]

Input: t = [30, 40, 50, 60]

Output: [1, 1, 1, 0]

Hints

    Try it first. Every hint reveals a bit more.

    Solution