Minimum Window Substring

Given two strings, original and check, return the minimum substring of original such that each character in check, including duplicates, are included in this substring. By "minimum", I mean the shortest substring. If two substrings that satisfy the condition has the same length, the one that comes lexicographically first are smaller.


  • original: The original string.
  • check: The string to check if a window contains it.


  • The smallest substring of original that satisfy the condition.


Example 1

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

Output: baec

Explanation: baec is the shortest substring of original that contains all of a, b, and c.


  • 1 <= len(check), len(original) <= 10^5
  • original and check both contains only upper case and lower case characters in English. The characters are case sensitive.

Try it yourself




Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

Contrary to popular belief, Lorem Ipsum is not simply random text.

1  >>> a = [1, 2, 3]
2  >>> a[-1]
3  3

Get premium for instant access to all content and solutions