Problem
You get two strings s and t. Find the shortest substring of s that contains every character of t. A substring is a part of the string with consecutive characters.
Repeated characters count. If a character appears two times in t, the substring must contain it at least two times. Uppercase and lowercase letters are different characters.
Return the shortest substring. If no substring contains all the characters, return the empty string "". The tests make sure that only one shortest substring exists.
Example 1
- Input:
- s = "QWBXAQCWBA", t = "ABC"
- Output:
- "CWBA"
- Explanation:
- The substring
"CWBA"containsA,BandC. Each other substring with these three letters is longer.
Example 2
- Input:
- s = "aa", t = "aaa"
- Output:
- ""
- Explanation:
- The string
thas threeacharacters, butshas only two.
Example 3
- Input:
- s = "hello", t = "ll"
- Output:
- "ll"
Constraints
- m == s.length
- n == t.length
- 1 <= m, n <= 10^5
- s and t contain only uppercase and lowercase English letters.
Follow-up
Find a solution that runs in O(m + n) time, where m and n are the lengths of s and t.
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Longest Substring with At Most K Distinct Characters
Coding · Hash Table · Sliding Window · String
- Longest Substring Without Repeating Characters
Coding · Hash Table · Sliding Window · String
- Maximum Number of Occurrences of a Substring
Coding · Hash Table · Sliding Window · String
- Find All Anagrams in a String
Coding · Hash Table · Sliding Window · String
Sources · 2 references
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 6 records
Amazon
Leetcode 76. Minimum Window Substring
Reported Jul 28, 2025 · 1 source report
MID_LEVEL
Source snapshot: Nov 12, 2026
View sourceLinkedIn
Leetcode 76. Minimum Window Substring
Reported Sep 7, 2026 · 5 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceLyft
Leetcode 76. Minimum Window Substring
Reported Aug 1, 2026 · 8 source reports
MID_LEVEL, SENIOR
Source snapshot: Nov 12, 2026
View sourceMeta
Leetcode 76. Minimum Window Substring
Reported Apr 7, 2026 · 12 source reports
MID_LEVEL, SENIOR, STAFF
Source snapshot: Nov 12, 2026