You are given two strings S and T. Find the smallest substring in S that contains all characters of T (including frequency). If no such substring exists, return an empty string. If multiple answers exist, return any one. This problem simulates searching the smallest valid data segment that satisfies all required conditions.
Why this is asked
Tests sliding window deeply
Real use: search/filter systems
Example
Input:
S = ADOBECODEBANC
T = ABC
Output:
BANC
Examples
Example 1
Input: ADOBECODEBANC,ABC
Output: BANC
Example 2
Input: MYNAMEISJEFF,MJ
Output: MYNAMEISJ
Example 3
Input: AZOBECODEBANC,ABC
Output: BANC
Loading...
ADOBECODEBANC,ABC
BANC
Minimum Window Substring for Required Characters - Practice - Prepverse 🎓