DIY: Minimum Window Subsequence

Solve the interview question "Minimum Window Subsequence" in this lesson.

Problem statement

Given strings s and t, find the minimum (contiguous) substring w of s, so that t is a subsequence of s.

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.


The input will be two strings s and t. The following is an example input:

s = "abcdebdde"
t = "bde"


For the above input, the output will be:


The strings "bcde" and "bdde" are both minimum subsequences, but "bcde" occurs before "bdde".

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.