Minimum Window Substring
Hard Sliding Window AI round
s and t are strings of English letters.
A window is a stretch of s, taken without gaps, that holds every character of t as many times as t has it. An upper case letter and its lower case are different characters. The tests are made so that, when s has a window, exactly one window is the shortest.
Return the shortest window, or the empty string "" when s has none.
Example 1
Input: s = "aPxkzPPyQ", t = "PPk"
Output: "kzPP"
t needs P twice and k once. From the k to the second P after it is 4 characters; every other stretch with two P's and a k is longer.
Example 2
Input: s = "kayakSNOWhat", t = "tSk"
Output: "kSNOWhat"
Example 3
Input: s = "HelloWorld", t = "hw"
Output: ""
Constraints
1 ≤ s.length, t.length ≤ 10⁵sandthold only English letters, upper and lower case- When
shas a window, exactly one window is the shortest
Practice this in an AI round
30 minutes on this problem with an AI agent beside your code, then a report on your solution and how you used the agent.
Your first AI round is free.
Watch the explanation
More Sliding Window
- Longest Substring Without Repeating CharactersAI round · Medium
- Sliding Window MaximumAI round · Hard
- Minimum Size Subarray SumAI round · Medium
- Longest Substring with At Most K Distinct CharactersMedium
- Longest Repeating Character ReplacementMedium