Applied AI Engineer (LLM) coding learning path Level 3 This level · 4 of 27

Minimum Window Substring

Hard Sliding window

Problem

Given strings s and t, return the shortest substring of s that contains every character of t, including multiplicity. If several substrings have that length, return the first one that appears. If there is no such substring, return the empty string.

Original: LeetCode 76: Minimum Window Substring.

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`""`

Example 4

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

Constraints

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

Hints

Solution

Tried it yourself? The approach, complexity, and code stay hidden until you choose.

Sources (2)
  1. LeetCode 76: Minimum Window Substringleetcode.com
  2. Java SE 17 API: String.substringdocs.oracle.com
Previous
Next