25. Minimum Window Substring
Choose the shortest continuous part of the source that contains every character required by the target. Extra characters are allowed inside the chosen window, but required repeated characters must all be present.
Order within the target does not impose an order on the window. Follow the contract for ties and for the case where no covering window exists.
Example 1
Input
source="ADOBECODEBANC", target="ABC"
Output
"BANC"
Explanation: BANC covers A,B,C in length four; target order is not required.
Example 2
Input
source="AAABBC", target="AABC"
Output
"AABBC"
Explanation: Two A occurrences are necessary, so ABC alone would not cover the target.
Constraints
0 <= source.length, target.length <= 1050 <= character code <= 127- Matching is case-sensitive ASCII. Return the earliest start when minimum lengths tie.
Hints
Hint 1
Which target occurrences are still missing from the current window?
Hint 2
How do negative deficits represent surplus copies?
Hint 3
Grow until missing is zero; record and shrink while coverage survives.
Submissions
Your recent submissions for this problem.
Checking sign-in…
Discussion
Ask a question or share an approach. Posts are public; avoid personal information and mark solution spoilers clearly.
No discussion yet. Start the conversation with a question about this problem.
Checking sign-in…
Run your code to check the sample cases, or submit it to check the full validation suite.
Cover, shrink, and improve the best boundaries
"ADOBECODEBANC"
"ABC"
"BANC"