C++ | O(n) | store prev and next same char index for each
\nclass Solution {\npublic:\n    int mod=1000000007;\n    int uniqueLetterString(string s) \n    {\n        int n=s.size();\n        vector<int>pl(26,-1),pr(26,
```\nclass Solution {\npublic:\n    int mod=1000000007;\n    int uniqueLetterString(string s) \n    {\n        int n=s.size();\n        vector<int>pl(26,-1),pr(26,n);  \n        vector<int>left(n),right(n);   // To store index of prev same char on left and right side\n        for(int i=0;i<n;i++)\n        {\n            int x=s[i]-\'A\';\n            left[i]=pl[x];\n            pl[x]=i;\n        }\n        for(int i=n-1;i>=0;i--)\n        {\n            int x=s[i]-\'A\';\n            right[i]=pr[x];\n            pr[x]=i;\n        }\n        int res=0;\n        for(int i=0;i<n;i++)\n        {\n            int l=i-left[i];\n            int r=right[i]-i;\n            res=(res+r*l)%mod;\n        }\n        return res;\n    }\n};\n```
[]