Python O(N)
Basic idea: for each letter in \'A\'-\'Z\', count the number of substrings ending at position i that contain strictly one letter. For position i, sum of counts 
Basic idea: for each letter in \'A\'-\'Z\', count the number of substrings ending at position ```i``` that contain strictly one letter. For position ```i```, sum of counts for letters \'A\'-\'Z\' gives us the total number of unique charaters in substrings ending at ```i```. We can then just accumulate all the sums.\n```\nclass Solution:\n    def uniqueLetterString(self, s: str) -> int:\n        curr = collections.defaultdict(lambda: -1)\n        prev = collections.defaultdict(lambda: -1)\n        \n        cnt = 0\n        for i, c in enumerate(s):\n            prev[c] = curr[c]\n            curr[c] = i\n            \n            for letter in string.ascii_uppercase:\n\t\t\t\t# add the number of substrings ending at i that has strictly one entry of letter\n                cnt += curr[letter] - prev[letter]\n            \n        return cnt\n```\nOptimized version:\n```\nclass Solution:\n    def uniqueLetterString(self, s: str) -> int:\n        curr = collections.defaultdict(lambda: -1)\n        prev = collections.defaultdict(lambda: -1)\n        \n        cnt = 0\n        delta = 0\n        for i, c in enumerate(s):\n            delta += i - 2 * curr[c] + prev[c]\n            cnt += delta\n\n            prev[c] = curr[c]\n            curr[c] = i\n            \n            \n        return cnt\n```
[]