Skip to main content

Minimum Deletion Window Equalizer

medium
StringHash TableSliding WindowSliding Window
Asked atAmazonGoogleMicrosoftBloombergUberLinkedin

Problem Description

You are given two strings `source` and `pattern`. Find the **minimum length** contiguous substring of `source` that contains **all characters** of `pattern` (including duplicates). Return the substring itself. If no such window exists, return an empty string `""`.

**Example 1:**
```
Input: source = "xyzabcxyz", pattern = "bca"
Output: "abc"
Explanation: "abc" (length 3) is the shortest window containing 'a', 'b', and 'c'.
```

**Example 2:**
```
Input: source = "abfgcd", pattern = "acd"
Output: "abfgcd"
Explanation: The entire string is the minimum window.
```

Constraints

  • 1 <= source.length <= 10^5
  • 1 <= pattern.length <= 10^4
  • source and pattern consist of lowercase and uppercase English letters

Follow-up

What if `pattern` can contain wildcard characters that match any single letter? How would you adapt the sliding window approach?

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.