Minimum Window Subsequence
Try to solve the Minimum Window Subsequence problem.
We'll cover the following
Statement#
Given two strings, str1 and str2, find the shortest substring in str1 such that str2 is a subsequence of that substring.
A substring is defined as a contiguous sequence of characters within a string. A subsequence is a sequence that can be derived from another sequence by deleting zero or more elements without changing the order of the remaining elements.
Let’s say you have the following two strings:
str1 = “”
str2 = “”
In this example, “” is a substring of str1, from which we can derive str2 simply by deleting both the instances of the character . Therefore, str2 is a subsequence of this substring. Since this substring is the shortest among all the substrings in which str2 is present as a subsequence, the function should return this substring, that is, “”.
If there is no substring in
str1that covers all characters instr2, return an empty string.
If there are multiple minimum-length substrings that meet the subsequence requirement, return the one with the left-most starting index.
Constraints:
-
str1.length -
str2.length str1andstr2consist of uppercase and lowercase English letters.
Examples#
1 of 2
2 of 2
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Minimum Window Subsequence
What are valid substrings of “Educative”?
“tive”
“ude”
“cat”
“vit”
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.
Try it yourself#
Implement your solution in main.py in the following coding playground:
Solution: Find Maximum in Sliding Window
Solution: Minimum Window Subsequence