Number of substrings with exactly k distinct characters
atMost(A, K) computes the number of substrings with at most K distinct characters.
A substring with at most K distinct characters has either exactly K, or at most K-1, distinct characters. So, atMost(A, K) - atMost(A, K-1) is the number of substrings with exactly K distinct characters.