Home
Log in
DescriptionSubmissionsSolution
DescriptionSubmissionsSolution
Loading...

Log in to run or submit

temperatures =

Codey

Practise coding problems, test your solutions and track your progress.

Explore

  • Problems
  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

© 2026 Codey. Personal learning project.

Solution
Updated: 2026-02-23

Idea

Use a monotonic decreasing stack of indices.

Approach

Scan temperatures. While the current temperature is higher than the temperature at the stack top, pop that index and set the answer as the distance to the current day.

Why it works

Each index stays on the stack until a warmer day appears; the first warmer day is exactly when it gets popped.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)
Solution
Updated: 2026-02-23

Idea

Use a monotonic decreasing stack of indices.

Approach

Scan temperatures. While the current temperature is higher than the temperature at the stack top, pop that index and set the answer as the distance to the current day.

Why it works

Each index stays on the stack until a warmer day appears; the first warmer day is exactly when it gets popped.

Code
Loading...
Complexity
Time: O(n)
Space: O(n)