Try all substrings. For each, count character frequencies and check if you can make all characters the same with at most k replacements.
There are substrings. Counting frequencies for each takes . Total: .
For , that's operations. Far too slow.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
The trap
Try all substrings. For each, count character frequencies and check if you can make all characters the same with at most k replacements.
There are substrings. Counting frequencies for each takes . Total: .
For , that's operations. Far too slow.