Python - DP solution O(N)
"d" stores the last 2 indices of the current letter. "a" stands for the sum of results of all the substrings ending with the current letter "c". \n\nclass Solut
"d" stores the last 2 indices of the current letter. "a" stands for the sum of results of all the substrings ending with the current letter "c". \n```\nclass Solution:\n    def uniqueLetterString(self, s: str) -> int:\n        d = defaultdict(lambda:(0, 0))\n        res = a = 0\n        for i, c in enumerate(s, 1):\n            a += i - 2 * (d[c][1] - d[c][0]) - d[c][0]\n            res += a\n            d[c] = (d[c][1], i)\n        return res\n```
['Dynamic Programming', 'Python', 'Python3']