|
1 | 1 | /**
|
2 | 2 | * 76
|
3 | 3 | * Minimum Window Substring
|
4 |
| - ** |
| 4 | + ** |
5 | 5 | * Given two strings s and t of lengths m and n respectively,
|
6 |
| - * return the minimum window substring of s |
7 |
| - * such that every character in t (including duplicates) is included in the window. |
8 |
| - * |
| 6 | + * return the minimum window substring of s such that |
| 7 | + * every character in t (including duplicates) is included in the window. |
9 | 8 | * If there is no such substring, return the empty string "".
|
10 |
| - * |
| 9 | + * |
11 | 10 | * The testcases will be generated such that the answer is unique.
|
12 |
| - * |
13 |
| - * Follow up: Could you find an algorithm that runs in O(m + n) time? |
14 |
| - * |
| 11 | + * |
| 12 | + * Example 1: |
| 13 | + * Input: s = "ADOBECODEBANC", t = "ABC" |
| 14 | + * Output: "BANC" |
| 15 | + * Explanation: The minimum window substring "BANC" includes 'A', 'B', and 'C' from string t. |
| 16 | + * |
| 17 | + * Example 2: |
| 18 | + * Input: s = "a", t = "a" |
| 19 | + * Output: "a" |
| 20 | + * Explanation: The entire string s is the minimum window. |
| 21 | + * |
| 22 | + * Example 3: |
| 23 | + * Input: s = "a", t = "aa" |
| 24 | + * Output: "" |
| 25 | + * Explanation: |
| 26 | + * Both 'a's from t must be included in the window. |
| 27 | + * Since the largest window of s only has one 'a', return empty string. |
| 28 | + * |
| 29 | + * Constraints: |
| 30 | + * • m == s.length |
| 31 | + * • n == t.length |
| 32 | + * • 1 <= m, n <= 10^5 |
| 33 | + * • s and t consist of uppercase and lowercase English letters. |
| 34 | + * |
| 35 | + * Follow up: |
| 36 | + * Could you find an algorithm that runs in O(m + n) time? |
| 37 | + * |
| 38 | + * Hint 1: |
| 39 | + * Use two pointers to create a window of letters in s, which would have all the characters from t. |
| 40 | + * |
| 41 | + * Hint 2: |
| 42 | + * Expand the right pointer until all the characters of t are covered. |
| 43 | + * |
| 44 | + * Hint 3: |
| 45 | + * Once all the characters are covered, |
| 46 | + * move the left pointer and ensure that |
| 47 | + * all the characters are still covered to minimize the subarray size. |
| 48 | + * |
| 49 | + * Hint 4: |
| 50 | + * Continue expanding the right and left pointers until you reach the end of s. |
| 51 | + ** |
15 | 52 | * https://leetcode.com/problems/minimum-window-substring/
|
16 |
| - */ |
| 53 | +***/ |
17 | 54 |
|
18 | 55 | using System.Collections.Generic;
|
19 | 56 |
|
|
0 commit comments