Skip to content

Commit 7cdad97

Browse files
committed
problem: 0076. Minimum Window Substring
1 parent 4d642ea commit 7cdad97

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

Diff for: solutions/solution_0076/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# 0076. [Minimum Window Substring](https://leetcode.com/problems/minimum-window-substring/description/?envType=study-plan-v2&envId=top-interview-150)
2+
3+
Given two strings `s` and `t` of lengths `m` and `n` respectively, return _the **minimum window substring** of s such that every character in t **(including duplicates)** is included in the window._ If there is no such substring, return the empty string `""`.
4+
5+
The testcases will be generated such that the answer is `unique`.
6+
7+
### **Example 1:**
8+
9+
<pre><code><strong>Input:</strong> s = "ADOBECODEBANC", t = "ABC"
10+
<strong>Output:</strong> "BANC"
11+
<strong>Explanation:</strong> The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t.
12+
</code></pre>
13+
14+
### **Example 2:**
15+
16+
<pre><code><strong>Input:</strong> s = "a", t = "a"
17+
<strong>Output:</strong> "a"
18+
<strong>Explanation:</strong> The entire string s is the minimum window.
19+
</code></pre>
20+
21+
### **Example 3:**
22+
23+
<pre><code><strong>Input:</strong> s = "a", t = "aa"
24+
<strong>Output:</strong> ""
25+
<strong>Explanation:</strong> Both 'a's from t must be included in the window.
26+
Since the largest window of s only has one 'a', return empty string.
27+
</code></pre>
28+
29+
### **Constraints:**
30+
31+
- `m == s.length`
32+
- `n == t.length`
33+
- <code>1 <= m, n <= 10<sup>5</sup></code>
34+
- `s` and `t` consist of uppercase and lowercase English letters.
35+
36+
**Follow up:** Could you find an algorithm that runs in `O(m + n)` time?

Diff for: solutions/solution_0076/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Solution:
2+
def minWindow(self, s: str, t: str) -> str: ...

Diff for: solutions/solution_0076/test_solution.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from typing import TypedDict
2+
3+
import pytest
4+
5+
from . import Solution
6+
7+
8+
class InputDict(TypedDict):
9+
s: str
10+
t: str
11+
12+
13+
class CaseDict(TypedDict):
14+
input: InputDict
15+
expected: str
16+
17+
18+
test_cases: list[CaseDict] = [
19+
{
20+
'input': {
21+
's': 'ADOBECODEBANC',
22+
't': 'ABC',
23+
},
24+
'expected': 'BANC',
25+
},
26+
{
27+
'input': {
28+
's': 'a',
29+
't': 'a',
30+
},
31+
'expected': 'a',
32+
},
33+
{
34+
'input': {
35+
's': 'a',
36+
't': 'aa',
37+
},
38+
'expected': '',
39+
},
40+
]
41+
42+
43+
@pytest.mark.parametrize(
44+
'test_case',
45+
test_cases,
46+
)
47+
def test_solution(test_case: CaseDict):
48+
result = Solution().minWindow(**test_case['input'])
49+
assert result == test_case['expected']

0 commit comments

Comments
 (0)