Minimum Window Substring
Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Amazon reportedly put Minimum Window Substring in front of candidates in September 2026, and the input size is the first thing to respect. Both strings can hit 100000 characters, so checking every substring against t is dead on arrival. That's roughly ten billion windows before you even count characters. The pattern is a sliding window with a frequency map, and it's a classic for a reason. If you've got an OA coming, learn the expand-then-shrink rhythm cold. And if your head goes blank mid-assessment, StealthCoder runs invisibly as a safety net while you work.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two pointers and a need-count. Build a frequency map of t. Expand the right pointer, decrementing the need for each character, and track how many distinct characters are fully satisfied. When every one is satisfied, shrink from the left as far as you can while staying valid, and record the window if it's shorter than the best so far. Each pointer only moves forward, so it's O(n + m). Pitfalls: forgetting duplicates in t (the example with t = "aa" catches this), updating the satisfied count at the wrong moment, and breaking the tie rule. Only replace the best on a strictly shorter window, and the smallest start index comes for free. Use a map or a 128-slot array for printable ASCII. If you freeze on the shrink logic during the live OA, StealthCoder is the hedge that gets you unstuck.
Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.
You can drill Minimum Window Substring cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.
Get StealthCoderRelated leaked OAs
This OA pattern shows up on LeetCode as minimum window substring. If you have time before the OA, drill that.
You've seen the question.
Make sure you actually pass Amazon's OA.
Amazon reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Minimum Window Substring FAQ
How hard is Minimum Window Substring really?+
It's a hard-tagged problem, but the solution is short once you know the template. The difficulty is bookkeeping, not insight. Most failures come from mishandling duplicate characters or the moment you count a character as satisfied. Write it twice from memory and it stops feeling hard.
What's the trick to avoid brute force?+
Never rescan. Keep a frequency map of t and a counter of how many distinct characters are fully covered. Move the right pointer to cover everything, then move the left pointer to tighten. Each index is visited at most twice, which gives linear time for strings up to 100000.
How do I handle duplicates in t?+
Store counts, not a set. Decrement the need count when a character enters the window and only treat it as satisfied when its count reaches zero. The example with s = "a" and t = "aa" returns an empty string precisely because one copy isn't enough.
What about ties between equal-length windows?+
The problem wants the smallest starting index. Scanning left to right and only updating your best window when a new one is strictly shorter gives you that automatically. Don't use a less-than-or-equal comparison, or you'll overwrite the earlier window with a later one.
How do I prepare for this in 48 hours?+
Code the sliding window template from scratch until you can do it without peeking. Then test the edge cases: t longer than s, single characters, all duplicates, and no valid window. Check that you return an empty string, not null. Two or three clean runs is enough for this pattern.