Dsa
Sliding Window
Medium
Smallest Window with All Characters
Given a string s and a string t, find the length of the smallest substring of s containing all the characters of t (including duplicates). If no substring exists, return 0.
Input:
- The first line contains string s (1 <= |s| <= 100,000).
- The second line contains string t (1 <= |t| <= 26).
Output:
- Print the length of the smallest window that contains all characters from t.
Example:
Input:
ADOBECODEBANC
ABC
Output:
4
Key concepts
sliding_windowstringhash_map
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now