DiffPush Tier Sliding Window · Hard Problems O(m + n) · O(n)
A fulfillment scanner reads one long stream of crate codes and must locate the shortest contiguous stretch that contains every part code on today's pick list — counting multiplicity, so a part demanded twice must appear twice. The scanner slides a frame over the stream, records the first complete covering stretch, then keeps tightening from the left as long as coverage holds, tracking the shortest frame ever seen.
Input: Two strings: s (the crate-code stream) and t (the pick list).
Output: Return the shortest substring of s covering every character of t with multiplicity, or an empty string if none exists.
1 <= s.length, t.length <= 10^5s and t consist of uppercase and lowercase English lettersThe answer is guaranteed to be unique when it existsInput: {"s":"ADOBECODEBANC","t":"ABC"}
Output: "BANC"
The tail "BANC" is the shortest stretch holding A, B and C simultaneously.
Input: {"s":"a","t":"a"}
Output: "a"
The single character covers the demand exactly.