Minimum Window Substring
You get two strings, s and t. Find the shortest piece of s, letters in a row, that contains every letter of t, as many times as t has it. If there is none, the answer is an empty string. Our example: s = "baxcab", t = "abc" — the answer is "cab".
- input
sandt: strings of letters;aandAare different characters.- returns
- The shortest substring of
sthat has every character oft, each at least as many times as int;""if there is none. - constraints
- 1 ≤ s.length ≤ 10000
- 1 ≤ t.length ≤ 10000
- s, t: uppercase and lowercase English letters
- the shortest window is one string, or there is none
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {string} s
* @param {string} t
* @return {string}
*/
function minWindow(s, t) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more sliding window problems
- 643Maximum Average Subarray IEasysolve
- 28Find the Index of the First Occurrence in a StringEasysolve
- 3Longest Substring Without Repeating CharactersMediumsolve
- 209Minimum Size Subarray SumMediumsolve
- 424Longest Repeating Character ReplacementMediumsolve
- 567Permutation in StringMediumsolve
- 30Substring with Concatenation of All WordsHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.