C++ Time: O(n), Space: O(1)
\t\t\t\n\nclass Solution {\npublic:\n    int cur[26], prev[26]; // occurences. at first 0, so I\'ll use 1-based indexing\n    int uniqueLetterString(string& s) 
\t\t\t\n```\nclass Solution {\npublic:\n    int cur[26], prev[26]; // occurences. at first 0, so I\'ll use 1-based indexing\n    int uniqueLetterString(string& s) {\n        int i, n = s.size(); \n        long long total = 0LL; char ch;\n\t\t/*\n\t\t\tprev - cur - next    trio of indexes of char ch\n\t\t\tin how many substrings ch with position cur will be unique?\n\t\t\tpotential starting points are [prev + 1, cur], ending points are[cur, next - 1]\n\t\t\tso each time total += (cur - prev) * (next - cur)\n\t\t*/\n        for(i = 1; i <= n; i++){\n            ch = s[i - 1] - \'A\';\n            total += (cur[ch] - prev[ch]) * (i - cur[ch]);\n            prev[ch] = cur[ch];\n            cur[ch] = i;\n        }\n\t\t// haven\'t counted last occurences yet. so IMAGINE each letter pushed-back to string s\n        for(ch = 0; ch < 26; ch++) total += (cur[ch] - prev[ch]) * (n + 1 - cur[ch]);\n        return total;\n    }\n};\n```
['C']