Stop comparing whole maps.
transcript
Your window slides in two updates. Good. Then you compare two whole maps. Every single window. A hundred checks per window. There is a better way.
Notice one thing. Only two counts change.
Keep one number, called matched. It counts mix tracks at exactly their needed count. A count reaches its need? Matched goes up. A count moves away from it? Matched goes down. Anything else? Matched stays put.
The mix is seven, two, seven. Two distinct tracks. Five, seven, two. Only track two is right. Matched is one. Five leaves. Seven joins and reaches two. Matched is two. Two of two. That window is a replay. Next slide. Seven drops, two goes past its need. Matched falls to zero. The near miss is caught.
Each slide changes two counts and maybe matched. No map comparison. No loop over the mix.
Do not compare the whole thing. Track what changed.
Full breakdown in the lecture.