FastPrepMinimum Window Substring
Problems/Minimum Window Substring

Minimum Window Substring

Character.AI logoCharacter.AI● HardNEW GRADPHONE SCREEN
QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report names LeetCode 76 without reproducing its statement. The judged task follows that named exercise at about 99%.

Given strings s and t, find the shortest contiguous part of s that contains every character of t with its required multiplicity. Return that part of s. If no part qualifies, return an empty string.

For these test cases, a shortest qualifying window, when one exists, is unique. Treat uppercase and lowercase letters as different characters.

Function

minWindow(s: String, t: String) → String

Examples

Example 1

s = "ADOBECODEBANC"t = "ABC"return = "BANC"

The final four characters contain each required letter; no shorter window does.

Example 2

s = "a"t = "a"return = "a"

The only character supplies the target.

Example 3

s = "a"t = "aa"return = ""

There is only one copy of a, so no valid window exists.

Constraints

  • 1 ≤ s.length, t.length ≤ 10^5.
  • Both strings contain only uppercase and lowercase English letters.
  • The total input fits in memory.

More Character.AI problems

  • Spreadsheet With Dependent CellsPHONE SCREEN · Seen Sep 2026
  • Time-Based Key-Value Map With Floor and Ceiling QueriesPHONE SCREEN · Seen Apr 2025
  • Choose the Next Hidden-Word GuessPHONE SCREEN · Seen Jul 2024
See Character.AI hiring insights
Saved
class Solution {
    public String minWindow(String s, String t) {
        // Write your code here.
    }
}
Checking account…