Daily Temperatures

Python data engineering interview problem. Difficulty: intermediate. Pattern: Stacks. About 14 minutes. Part of the Pro drill bank.

Days until a warmer temperature for each day. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.

A weather report can tell a user how long they must wait for a warmer day. For each day, find the first later temperature that is strictly higher. Return one wait length for every temperature. Use 0 when no warmer later day exists. Write daily_temperatures(temperatures: list) -> list. For 73, the next warmer value is 74 1 day later; for 75, 76 is 4 days later, producing the first values [1, 1, 4]. The starter file already has the function name and harness print lines. Keep them and fill only the function body.

Requirements

  • Return the same number of positions as the input.
  • Use the nearest later strictly warmer temperature.
  • Use 0 when no later warmer day exists.

Constraints

  • Temperatures are numeric and the return type is a list of integers.
  • Equal temperatures are not warmer.

Examples

Input: daily_temperatures([73, 74, 75, 71, 69, 72, 76, 73]) Output: [1, 1, 4, 2, 1, 1, 0, 0] Next warmer offsets.

Topics: lakebench, python, monotonic stack, next greater.

More Python interview questions · All interview problems · Learn data engineering

intermediate

Daily Temperatures

Interview-style drill: Days until a warmer temperature for each day.

Implement `daily_temperatures(temperatures: list) -> list`. Example: `[73, 74, 75, 71, 69, 72, 76, 73]` → `[1, 1, 4, 2, 1, 1, 0, 0]`. Keep the harness.