Facebook Pixel

Minimum Window Substring

Given two strings, original and check, return the shortest substring of original that contains every character in check, including duplicates. If multiple valid substrings have the same length, return the lexicographically smallest one.

Parameters

  • original: The source string.
  • check: The required characters.

Result

  • The minimum valid window in original.

Examples

Example 1

Input: original = "cdbaebaecd", check = "abc"

Output: baec

Explanation: Both cdba and baec are valid windows of length 4. We return baec because it is lexicographically smaller.

Constraints

  • 1 <= len(check), len(original) <= 10^5
  • original and check contain only uppercase and lowercase English letters. Characters are case-sensitive.

Try it yourself

Solution

Invest in Yourself
Your new job is waiting. 83% of people that complete the program get a job offer. Unlock unlimited access to all content and features.
Go Pro