Problem intuition
The brute-force version tries every possible substring and checks whether it covers the target counts.
The optimal solution grows the window until all requirements are met, then shrinks from the left to make the valid window as small as possible.
Java solution ladder
The solutions below are ordered from least optimal to most optimal, so you can see the improvement path instead of only the final answer.