13 · Sliding Window

#76 Minimum Window Substring

Hardsolve on LeetCode ↗

frequently reported atAdobeByteDance / TikTokMetaLinkedInAirbnbAmazon

the problem

In plain words

Return the shortest substring of s that contains every character of t, including duplicates. Return "" if there is none.

in s = "ADOBECODEBANC", t = "ABC"

out "BANC"

in s = "a", t = "a"

out "a"

The whole string is the window.

in s = "a", t = "aa"

out ""

t needs two a's; s has one.

  • 1 ≤ s.length, t.length ≤ 10⁵
  • Upper- and lowercase English letters
  • The answer is unique

your turn

Try it before you peek

Read the examples, say the brute force out loud, then write code: here or on LeetCode ↗. Stuck for 20 minutes? Open one hint at a time.

Solve it in the browser

LeetCode-style: complete the class. Compiled by the real javac (Java 17) and judged right here — nothing is sent anywhere.

    Solutions are hidden so you can try first. Even 20 minutes of real effort makes the answer stick far better than reading it.

    Marking the problem solved, or opening every hint, also shows it.

    practise next

    Similar problems

    1. #567
      Permutation in String
      Mediumin Sliding Window
    2. #30
    3. #209
      Minimum Size Subarray Sum
      Mediumin Sliding Window