Design Gurus Logo
Minimum Window Substring (hard)

Problem Statement

Given a string s and t of length m and n respectively, find the smallest substring in a given string 's' that contains all the characters (including duplicate) of another string 't'. The order of characters in 't' doesn't matter, but the substring in 's' must include all characters of 't', possibly with additional characters.

If no such substring exists, return an empty string.

Examples

Example 1:

  • Input: s = "xyyzyzyx", t = "xyz"
  • Expected Output: "zyx"
  • Justification: "zyx" is the shortest substring of 's' that contains 'x', 'y', and 'z'.

Example 2:

  • Input: s = "abracadabra", t = "aa"
  • Expected Output: "ada"
  • Justification: "ada" at the end of 's' is the shortest substring containing all 'a's in 't'.

Example 3:

  • Input: s = "welcomeback", t = "ole"
  • Expected Output: "elco"
  • Justification: "elco" includes 'o', 'l', and 'e', fulfilling the requirements with the minimum length.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory