Practice: Daily Temperatures
Problem: https://leetcode.com/problems/daily-temperatures/
Recognition reminder: for each day you want the number of days until a warmer one. “How far until something larger” is the next-greater cue, the high-value monotonic-stack signal from this week.
Before you start (the five-beat rhythm)
- Your Pattern Card for this week is already written.
- Name the pattern aloud and write your approach as a plain-English comment before any code.
- Struggle floor: 25 minutes unaided. No hints, no AI, no Discuss tab.
- If stuck past the floor, ask the tutor for a hint. Six rungs, one per ask.
- Debrief in your commit message before moving to the next problem.
Your target
Fill these in yourself before you look at anyone else’s solution:
Target time complexity: ____
Target space complexity: ____
The brute force scans forward from each day to find the next warmer one, which is O(n^2). A monotonic stack does it in one pass. Two decisions to make and defend: do you push values or indices, and is the stack you maintain increasing or decreasing? Tie each choice to what the answer has to report.
Where your code goes
Write your solution as a function daily_temperatures(temperatures: list[int]) -> list[int] in a file named solution.py in your own work repo (see getting-started.md), not in the course repo. This folder ships only the problem spec and a provided-example test (tests/test_provided.py) so you can check the given cases locally before you submit to LeetCode’s judge. The judge is the oracle; the tutor will not confirm your answer by reading it.
Debrief (paste into your commit message)
1. What pattern did this turn out to be?
2. What was the trigger phrase or input shape that should have made me reach for it?
3. What was the time and space complexity, and what would dominate at scale?
4. What edge case would have broken my first attempt?
5. What would I do differently in three days when I see this cold?