Minimum Contiguous Coverage Window
Problem Description
You are given a string `text` and a string `required`. Find the minimum-length contiguous substring of `text` that contains every character of `required` (including duplicates). Return the substring itself. If no valid window exists, return an empty string `""`.
**Example 1:**
```
Input: text = "CLOUDYSKYBRIGHT", required = "SKY"
Output: "SKYB"
Explanation: "SKY" appears starting at index 5, length 3. But checking all substrings:
"SKY" (indices 5-7) contains S, K, Y. That's length 3. But let's verify — 'S' at idx 5, 'K' at idx 6, 'Y' at idx 7. That's already the shortest at length 3.
Actually: text="CLOUDYSKYBRIGHT", indices: C(0)L(1)O(2)U(3)D(4)Y(5)S(6)K(7)Y(8)B(9)R(10)I(11)G(12)H(13)T(14). required="SKY" needs S,K,Y. Shortest window: "SKY" at [6,7,8], length 3.
```
**Example 2:**
```
Input: text = "adobecodebanc", required = "bca"
Output: "banc"
Explanation: The window "banc" (indices 9-12) contains 'b','a','n','c' — covers 'b','c','a'. Length 4 is the minimum.
```
Constraints
- 1 <= text.length <= 100000
- 1 <= required.length <= 1000
- text and required consist of uppercase and lowercase English letters
Follow-up
What if `required` can contain wildcard characters ('?') that match any single character in `text`?
Hints
Try the problem first. If you get stuck, you can reveal hints one at a time.
Solution
Leaderboard
No entries yet for python.
Be the first — submit an accepted solution.