c++ 95% o(n). easy to remember, explain and impl in 5mins. save ur time for extra two problems
\n#include <string>\n#include <vector>\n#include <iostream>\n\nusing namespace std;\n\nconst int MOD = 1e9 + 7;\n\nclass Solution {\npublic:\n    int uniqueLett
```\n#include <string>\n#include <vector>\n#include <iostream>\n\nusing namespace std;\n\nconst int MOD = 1e9 + 7;\n\nclass Solution {\npublic:\n    int uniqueLetterString(string str) {\n        int n = str.length();\n\n        vector<int> prev(26, -1);\n        vector<int> next(26, n);\n\n        vector<int> plen(n, 0);\n        for (int i = 0; i < n; ++i) {\n            plen[i] = i - prev[str[i] - \'A\'];\n            prev[str[i] - \'A\'] = i;\n        }\n\n        int res = 0;\n        for (int i = n - 1; i >= 0; --i) {\n            int nlen = next[str[i] - \'A\'] - i;\n            res += ((plen[i] * nlen) % MOD);\n            next[str[i] - \'A\'] = i;\n        }\n        return res;\n    }\n};\n\n#if DEBUG\nint main(int argc, char** argv) {\n    return 0;\n}\n#endif\n\n```
[]