Skip to interview prep
Apexed
Problem list123 / 125

123. Minimum Window Substring

HardString algorithms

Return the shortest substring of s that contains every character of t, including repeats (if t has two "a"s, the window needs two). If several shortest windows exist, return the leftmost. Return an empty string if no window exists.

Example 1

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

Constraints

  • 1 ≤ s.length, t.length ≤ 10⁵
  • Characters are ASCII letters

Tab indents · Ctrl/⌘ + Enter runs · Esc then Tab leaves the editor

Run checks these cases; the expected output comes from the reference solution. Submit judges all 5 hidden and sample tests.

Code runs only in your browser in an isolated sandbox. Progress and submissions are saved on this device.

Minimum Window Substring — coding interview practice — Apexed