res to 0 to store the count of special substrings.d to keep track of the last seen index of each character.l to 0 to represent the start of the current window.i to represent the end of the current window.c at index i, check if c is in the dictionary d and if the last seen index is within the current window.l to be one more than the last seen index of c.c in the dictionary d.i - l + 1) to res.res as the final count of special substrings.