FastPrepMinimum Window Substring
Problems/Minimum Window Substring

Minimum Window Substring

Amazon logoAmazon● HardFULLTIMEINTERNPHONE SCREENONSITE INTERVIEW
QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon SDE2 interview list as the canonical Minimum Window Substring exercise. The source does not state no-solution behavior, tie-breaking, character domain, or bounds; this practice version returns the empty string when no window exists, chooses the earliest start among equally short windows, treats printable ASCII case-sensitively, and limits each input to 100,000 characters. Problem match confidence: approximately 98%.

Given non-empty strings s and t, return the shortest contiguous substring of s that contains every character of t, including duplicate occurrences.

If no window exists, return the empty string. If several shortest windows exist, return the one with the smallest starting index.

Function

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

Examples

Example 1

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

BANC is the shortest window containing A, B, and C.

Example 2

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

The whole one-character string is the answer.

Example 3

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

The source does not contain enough copies of a.

Constraints

  • 1 ≤ s.length, t.length ≤ 100000.
  • s and t contain printable ASCII characters.
  • The total input length fits in memory.

Source note: Interview prompt excerpt preserved as source evidence.

More Amazon problems

  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
See Amazon hiring insights
Saved
class Solution {
    public String minWindow(String s, String t) {
        // write your code here
    }
}
Checking account…