contains category wise problems(data structures, competitive) of popular platforms.
View the Project on GitHub mayankdutta/category-wise-problems
2262. Total Appeal of A String
total no. of substring - total substring where character is absent
using ll = long long;
class Solution {
public:
ll fun(const string& s, const char& c) {
ll count = 0;
ll ans = 0;
ll n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] == c) {
ans += (count * (count + 1)) / 2;
count = 0;
}
else {
count ++;
}
}
ans += (count * (count + 1)) / 2;
return (n * (n + 1)/2) - ans;
}
long long appealSum(string s) {
ll ans = 0;
for (char c = 'a'; c <= 'z'; c++) {
ans += fun(s, c);
}
return ans;
}
};