Pattern Recognition Drill
Medium Sliding Window
The Problem
Given string s and integer k, find the longest substring where you can replace at most k characters to make all characters the same.
What approach would you use?
Think about it before scrolling down.
Window is valid when (window_size - max_freq_char) <= k. Expand right, shrink left when invalid. O(n).
Binary search on answer length, check each length feasibility. O(n log n).
Common Trap
You don't need to update max_freq when shrinking — the window only grows when a better max is found.