Module 7 · Sliding Window · Sliding Window Advanced

Maximum occurrences of a substring

Only substrings of length minSize need counting: a longer one that qualifies contains its first minSize characters, which occur at least as often. Slide a window of that size, track each character's last index to know how many distinct letters it holds, and count every window within maxLetters.