Skip to content

Add DailyTemperature coding question -> leetcode 739 #349

@technologic-technologic

Description

Is your feature request related to a problem? Please describe.
The repository currently lacks examples of the monotonic stack pattern. This pattern appears in many interview-style array problems, but there is no dedicated example to reference here.

Describe the solution you'd like
Add a single, self-contained example implementing “Daily Temperatures” (LeetCode 739) using a monotonic stack of indices.

  • Path: src/codingquestions/leetcode/ds/DailyTemperatures.java
  • Contents: a public class DailyTemperatures with a method int[] dailyTemperatures(int[] t) and a minimal main to run a few sample cases.
  • No changes to other folders or project settings.

Describe alternatives you've considered

  • Other very simple problems (Two Sum, Valid Parentheses). These add little new value so I'm trying something a little bit different, and to be honest, one of my favorites coding questions.
  • Larger data structures (LRU cache, Fenwick/Segment Tree). Useful, but they require more boilerplate and touch more files, which increases review time.

Additional context

  • Approach: one pass with a decreasing stack (indices). When a warmer day arrives, pop and set distance.
  • Complexity: O(n) time, O(n) space.
  • Example cases to include in main:
    [73,74,75,71,69,72,76,73] -> [1,1,4,2,1,1,0,0],
    [30,40,50,60] -> [1,1,1,0],
    [90,80,70,60] -> [0,0,0,0],
    [] -> [], [42] -> [0].

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions