Skip to main content
Advancedcoding Verified

Given a string and a pattern, find the smallest window of the string that contains all characters of the pattern (with multiplicity).

ReportedSource: GeeksforGeeks interview experience: LinkedIn, experienced

Quick answerFree

Sliding window with a need-count map and a single missing counter: expand right until all needed, then shrink left while valid, track the minimum. O(n + m).

Detailed answer· 89 words

Pro

Unlock the full answer with Pro

Get a 89-word model answer and a runnable reference solution, plus 82 more DSA questions.

Reference solution· runs in the browser sandbox

Pro
Unlock with Pro

+ 82 more DSA questions in Pro, each with the full answer.

Discussion