From 05922ecbff24c3110f1dd1ac0c30ad21a11f3ed6 Mon Sep 17 00:00:00 2001 From: wazedkhan Date: Sun, 19 Jul 2026 09:03:50 +0600 Subject: [PATCH] Leetcode-739: Daily Temperatures --- LeetCode/medium/daily_temperatures_739.py | 15 +++++++++++++++ tests/test_leetcode_medium.py | 17 +++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 LeetCode/medium/daily_temperatures_739.py diff --git a/LeetCode/medium/daily_temperatures_739.py b/LeetCode/medium/daily_temperatures_739.py new file mode 100644 index 0000000..e362564 --- /dev/null +++ b/LeetCode/medium/daily_temperatures_739.py @@ -0,0 +1,15 @@ +from typing import List + + +class Solution: + def dailyTemperatures(self, temperatures: List[int]) -> List[int]: + res = [0] * len(temperatures) + stack = [] + + for idx, temp in enumerate(temperatures): + while stack and temperatures[stack[-1]] < temp: + prev_idx = stack.pop() + res[prev_idx] = idx - prev_idx + stack.append(idx) + + return res diff --git a/tests/test_leetcode_medium.py b/tests/test_leetcode_medium.py index bc84628..9cfe8d7 100644 --- a/tests/test_leetcode_medium.py +++ b/tests/test_leetcode_medium.py @@ -225,6 +225,23 @@ def test_eval_rpn(tokens, expected): assert result == expected, f"expected: {expected}, but got: {result}, input: {tokens}" +@pytest.mark.parametrize( + "temperatures, expected", + [ + ([73, 74, 75, 71, 69, 72, 76, 73], [1, 1, 4, 2, 1, 1, 0, 0]), + ([30, 40, 50, 60], [1, 1, 1, 0]), + ([30, 60, 90], [1, 1, 0]), + ([73, 75, 71, 69, 72], [1, 0, 2, 1, 0]), + ], +) +def test_daily_temperatures(temperatures, expected): + from LeetCode.medium.daily_temperatures_739 import Solution + + res = Solution().dailyTemperatures(temperatures) + + assert res == expected, f"expected {expected}, but got {res}, input: {temperatures}" + + # 05: Longest Palindromic Substring # https://leetcode.com/problems/longest-palindromic-substring/?envType=problem-list-v2&envId=hash-table