Sliding Window Longest or shortest window
177. Minimum Window Subsequence
You are given two strings, s and t. Return the shortest substring of s that contains t as a
subsequence.
A substring is a block of letters that sit next to each other in s. A block contains t as a
subsequence when the letters of t appear in it in the same order, though not necessarily next to each
other. For t = "ace", the block "abcde" works: it has an a, later a c, and later an e. The block
"eca" does not. Each letter of t needs its own position, so t = "oo" needs two os.
If several substrings share the shortest length, return the one that starts first. If no substring works,
return the empty string. Answers are shown in double quotes, so an empty answer shows as "".
Example 1
Input: s = "programming", t = "rmn"
"rammin"Explanation: "rammin" has an r, then an m, then an n, and no shorter block does. The block that starts at the
first r, "rogrammin", works too, but it is longer.
Example 2
Input: s = "cabbage", t = "ba"
"ba"Explanation: "ab" at index 1 has both letters, but in the wrong order. The shortest block with a b and then an a
is "ba", at index 3.
Example 3
Input: s = "stone", t = "nest"
""Explanation: Every letter of t is in s, but no s comes after the n and the e. No block contains t in
order, so the answer is the empty string.
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ s.length ≤ 1051 ≤ t.length ≤ 100sandthold lowercase English letters only.
Clarifying questions
What you would ask an interviewer before writing any code.