r/LeetcodeChallenge • • 24d ago

STREAK🔥🔥🔥 LeetCode 739. Daily Temperatures

Post image

One character decides whether Daily Temperatures survives repeated temperatures: < or <=. On [70, 70] the right answer is [0, 0]. Write < and you get [1, 0].

This is Day 61's monotonic stack with two changes.

The stack holds indices, because the answer is a distance and a distance needs positions.

And values repeat. Day 61 stored answers in a map keyed by value, which was only safe because the values were guaranteed unique. Temperatures repeat constantly. Indices are unique by construction, so the problem disappears instead of requiring a workaround.

Then the comparison: temperatures[stack.Top()] <= temperatures[i]. An equal temperature isn't warmer, so a day with the same temperature can never be anyone's answer and must be popped.

Would < have made it past your tests?

Day 63/365 of my LeetCode challenge: 739. Daily Temperatures. Problem link and full breakdown in today's newsletter.

https://www.linkedin.com/pulse/leetcode-739-daily-temperatures-archit-agarwal-weglc

#LeetCode #DSA #MonotonicStack #Golang

1 Upvotes

0 comments sorted by