DIY: Minimum Window Subsequence
Solve the interview question "Minimum Window Subsequence" in this lesson.
We'll cover the following
Problem statement
Given strings S
and T
, find the minimum (contiguous) substring W
of S
, so that T
is a subsequence of W
.
If there is no window in S
that covers all characters in T
, return an empty string ""
. If there are multiple minimum-length windows, return the one with the left-most starting index.
Input
The input will be two strings S
and T
. The following is an example input:
S = "abcdebdde"
T = "bde"
Output
For the above input, the output will be:
"bcde"
The strings "bcde"
and "bdde"
are both minimum subsequences, but "bcde"
occurs before "bdde"
.
Coding exercise
For this coding exercise, you need to implement the min_window(S, T)
function, where S
and T
are the provided strings. The function should return the minimum subsequence of T
that exists in S
.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.