The Minimum Window Subsequence problem gives you two strings S and T. Find the minimum length window (substring of S) that contains T as a subsequence. Unlike "contains T as a substring," T's characters must appear in order within the window but not necessarily consecutively. This Minimum Window Subsequence coding problem requires a two-pass sliding pointer approach or dynamic programming.
Meta, eBay, LinkedIn, and Google ask this because it's a harder cousin of the classic Minimum Window Substring but with the subsequence condition instead of full character coverage. It tests whether candidates can apply the sliding window interview pattern to subsequence matching — a non-trivial adaptation. The sliding window, string, and dynamic programming interview pattern is the core.
Two-pointer / greedy scan. For each starting position in S, scan forward to find the end of the smallest window containing T as a subsequence. Then scan backwards from that end to find the tightest starting position. Track the minimum window length found. Alternatively, use DP: dp[i][j] = starting index in S such that S[dp[i][j]..i] contains T[0..j-1] as subsequence. Time: O(|S| * |T|).
S = "abcde", T = "ace".
S = "abcbdaace", T = "ace":
Minimum Window Subsequence is an excellent advanced follow-up to Minimum Window Substring. The key distinction: substring requires all characters present (use counts), subsequence requires ordered occurrence (use pointers). The backward scan after finding a window end is the unique insight here — it finds the tightest possible starting point for that end, minimizing window length. Practice both variants together to internalize the difference in approach and implementation.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Minimum Number of Flips to Make the Binary String Alternating | Medium | Solve | |
| Jump Game VII | Medium | Solve | |
| Count The Repetitions | Hard | Solve | |
| Encode String with Shortest Length | Hard | Solve | |
| Minimum Distance to Type a Word Using Two Fingers | Hard | Solve |