3
long long appealSum(string s) {6
for (char ch = 'a'; ch <= 'z'; ch++) // we are finding the number of substrings containing at7
// least 1 occurence of ch9
int prev = 0; // prev will store the previous index of the charcter ch10
for (int i = 0; i < n; i++) {12
prev = i + 1; // if the current character is equal to ch , then the13
// no. of substring ending at i and having at least one14
// occurence of ch will be i+1 .16
ans += prev; // else the no. of substrings ending at i and having at17
// least one occurence of ch will be the equal to, the18
// previous index of ch.21
return ans; // TC - O(n*26) , SC - O(1)