...

/

Minimum Window Substring

Minimum Window Substring

Try to solve the Minimum Window Substring problem.

Statement

Given two strings, s and t, find the minimum window substring in s, which has the following properties:

  1. It is the shortest substring of s that includes all of the characters present in t.

  2. It must contain at least the same frequency of each character as in t.

  3. The order of the characters does not matter here.

Note: If there are multiple valid minimum window substrings, return any one of them.

Constraints:

  • Strings s and t consist of uppercase and lowercase English characters.

  • 1 \leq s.length, t.length 103\leq 10^3

Examples

canvasAnimation-image
1 / 3

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check that you’re solving the correct problem.

Minimum Window Substring

1.

What is the output if the following strings are given as input?

s = “bbaac”

t = “aba”

A.

“bba”

B.

“baa”

C.

“bbaa”

D.

“”


1 / 3

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6

Try it yourself

Implement your solution in the following coding playground:

C++
usercode > main.cpp
string MinWindow(string s, string t) {
// Replace this placeholder return statement with your code
return "";
}
Minimum Window Substring

Access this course and 1200+ top-rated courses and projects.