Minimum Window Substring
Updated
Problem statement
You are given two strings, s and t. Return the shortest contiguous substring of s that contains every character of t, counting repeats. For example, if t has two a characters, the substring must have at least two a characters.
Uppercase and lowercase letters are different characters. If several shortest substrings qualify, return the one that starts first. If no substring qualifies, return an empty string.
Function
minWindow(s: String, t: String) → StringExamples
Example 1
s = "DAEBFCAB"t = "ABC"return = "CAB"Three substrings hold A, B and C without any spare letters at the edges: "AEBFC", "BFCA" and "CAB". The shortest is "CAB", with length 3.
Example 2
s = "baacaba"t = "aab"return = "baa"t needs two a and one b. Both "baa" (starting at index 0) and "aba" (starting at index 4) qualify and have length 3. "baa" starts first, so it is the answer.
Example 3
s = "aAbB"t = "aa"return = ""t needs two lowercase a, but s has only one. The uppercase A is a different letter, so no substring qualifies.
Example 4
s = "q"t = "q"return = "q"The whole string is the only substring, and it holds the one letter t needs.
Constraints
1 <= s.length <= 5 * 10^41 <= t.length <= 5 * 10^4sandtcontain only English letters.
More Salesforce Phone Screen questions
- Detect a Cycle in a Linked ListPHONE SCREEN · Seen Oct 2026
- Find Rows Common to Two TablesPHONE SCREEN · Seen Oct 2026
- Merge Two Sorted Linked ListsPHONE SCREEN · Seen Oct 2026
- Minimum Window of Required WordsPHONE SCREEN · Seen Aug 2026
- Permutations of Unique CharactersPHONE SCREEN · Seen Aug 2026
- Optimal Account BalancingPHONE SCREEN · Seen Jul 2026
- Longest Increasing SubsequencePHONE SCREEN · Seen Jul 2026
- Maximal SquarePHONE SCREEN · Seen Jul 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
Similar questions at other companies
- Minimum Window SubstringLyft · PHONE SCREENLyft interview questions
- Minimum Window SubstringAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Minimum Window SubstringCharacter.AI · PHONE SCREEN
- Shortest Window Covering All LettersAdobe · PHONE SCREENAdobe interview questions
- Minimum Window SubstringWhatNot · PHONE SCREENWhatNot interview questions
- Minimum Window SubstringSambaNova Systems · PHONE SCREENSambaNova Systems interview questions
- Longest Substring Without Repeating CharactersAngel One · PHONE SCREEN
- Longest Substring Without Repeating CharactersNykaa · PHONE SCREENNykaa interview questions
- Longest Substring Without Repeating CharactersIBM · PHONE SCREENIBM interview questions
- Longest Substring Without Repeating CharactersTikTok · PHONE SCREENTikTok interview questions