Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Consider the set of substrings that end at a certain index i. Then, consider a specific alphabetic character. How do you count the number of substrings ending at index i that contain that character?
The number of substrings that contain the alphabetic character is equivalent to 1 plus the index of the last occurrence of the character before index i + 1.
The total appeal of all substrings ending at index i is the total sum of the number of substrings that contain each alphabetic character.
To find the total appeal of all substrings, we simply sum up the total appeal for each index.