Skip to content

Practice Minimum Window Substring

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#76
LeetCode Problem

Minimum Window Substring

Problem Statement

Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no such substring, return the empty string "". The testcases will be generated such that the answer is unique. Follow up: Could you find an algorithm that runs in O(m + n) time?

Source: Minimum Window Substring on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
s = "ADOBECODEBANC", t = "ABC"
Output
"BANC"

# Example 2

Input
s = "a", t = "a"
Output
"a"

# Example 3

Input
s = "a", t = "aa"
Output
""

Constraints

m == s.length
n == t.length
1 <= m, n <= 10^5
s and t consist of uppercase and lowercase English letters.

Related LeetCode Problems

Practice more problems similar to Minimum Window Substring.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.