Code
Loading editor...
Tap Analyze to see visualization
Click Analyze to visualize
See step-by-step execution, variables, and output
Variables
Run code to see variables
Output
Console output will appear here
Click Analyze to visualize
See step-by-step execution, variables, and output
Run code to see variables
Console output will appear here
Build a frequency map for t to know what characters are required. Expand the window rightward, tracking how many unique characters have met their required frequency (formed counter). Once all are met, shrink from the left to find the minimum valid window, updating the answer each time.
The formed counter tracks how many of t's unique characters are fully satisfied. Expanding right can only increase or maintain formed, while shrinking left can only decrease or maintain it. This monotonic behavior ensures we find the global minimum window efficiently.
Updated Feb 2026