Skip to main content
All Questions

Find the minimum window substring.

Medium
Unlock detailed company stats for this questionUpgrade

Given two strings s and t, return the shortest substring of s that contains every character of t, including repeats. If no such substring exists, return an empty string.

The characters can appear in any order within the substring. The tests only use inputs where the shortest substring is unique.

Example 1

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

BANC is the shortest substring that contains A, B and C.

Example 2

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

t needs two a characters, but s only has one.

Constraints

  • 1 <= s.length, t.length <= 100000
  • s and t contain only uppercase and lowercase English letters.
  • Letters are case-sensitive, so a doesn't match A.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.