Minimum Window Substring
Reported by candidates from Highspot's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt at Minimum Window Substring is ignoring duplicate letters in t. Highspot candidates reported this one in August 2024, and it's a textbook sliding window with a counting twist. You get s and t, and you return the shortest slice of s that covers every character of t with its full multiplicity. Case matters, and an empty string comes back if nothing fits. With strings up to 10^5, brute force dies fast. If the OA arrives and your mind goes blank, StealthCoder runs invisibly as a safety net while you work through it.
The problem
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.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two pointers plus a frequency map of t. Expand the right pointer, decrementing the need count for each character. Track a single counter, formed or missing, that tells you when every required character is satisfied. Once it hits zero, shrink from the left as far as the window stays valid, record the best length and start index, then drop the left character and keep going. The pitfall is checking validity by presence only. Example 3 breaks that: s = "a", t = "aa" needs two copies. Another trap is rescanning the whole map on every step, which turns O(n) into O(52n). Use the counter instead. Slice the answer once at the end, not during the loop. If you freeze during the live OA, StealthCoder is the hedge that surfaces this pattern while you type.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
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. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken.
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 Highspot's OA.
Highspot reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. 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 pattern is standard. Once you know the sliding window with a need-count map, it's about 25 lines. The difficulty is handling duplicates and shrink logic cleanly, not any exotic algorithm.
What's the trick to solve it in linear time?+
Keep a count map of t and a counter of how many required characters are still missing. Move the right pointer to grow the window, then move the left pointer to shrink it while the window stays valid. Each index is visited at most twice, so it's O(n).
Why does my solution fail on s = "a", t = "aa"?+
You're likely checking whether each character appears instead of how many times. t needs two a's and s has one, so the answer is an empty string. Count multiplicities, and only mark the window valid when every count is satisfied.
Does case sensitivity matter here?+
Yes. Uppercase and lowercase are different characters, so 'A' and 'a' are separate keys. Use a map or an array of 128 slots, or 52 with careful indexing. Don't lowercase the input or you'll return wrong windows.
How do I prepare for this in 48 hours?+
Write the sliding window from scratch twice without looking. Test on the three examples, then on a case with repeated letters in t. Practice returning the substring using a stored start index and best length, and handle the no-window case by returning an empty string.