C++ O(n)
\nclass Solution {\npublic:\n    int uniqueLetterString(string s) {\n        int n=s.size(); \n        vector<vector<int> > hash(26);\n        for(int i=0; i<26
```\nclass Solution {\npublic:\n    int uniqueLetterString(string s) {\n        int n=s.size(); \n        vector<vector<int> > hash(26);\n        for(int i=0; i<26; i++) hash[i]={-1,-1};\n        int ans=0, sum=0;\n        for(int i=0; i<n; i++) {\n            int idx=s[i]-\'A\';\n            sum+=(i-hash[idx][0])-(hash[idx][0]-hash[idx][1]);\n            hash[idx][1]=hash[idx][0], hash[idx][0]=i;\n            ans+=sum;\n        }\n        return ans;\n    }\n};\n```
[]