Simplest C++ solution
I wrote this after watching: https://www.youtube.com/watch?v=eN8zATT702M\n\n    int uniqueLetterString(string s) {\n        map<char, vector<int>> all_indexes;\
I wrote this after watching: https://www.youtube.com/watch?v=eN8zATT702M\n```\n    int uniqueLetterString(string s) {\n        map<char, vector<int>> all_indexes;\n        for(int i = 0; i < s.length(); ++i)\n            all_indexes[s[i]].push_back(i);\n        \n        int sum = 0;\n        for(auto p : all_indexes)\n        {\n            for(int i = 0; i < p.second.size(); ++i)\n            {\n                int left = (i == 0)?p.second[i]+1:p.second[i] - p.second[i-1];\n                int right = (i == p.second.size()-1)?s.length() - p.second[i]:p.second[i+1] - p.second[i];\n                sum += left * right;\n            }\n        }\n        return sum;\n    }\n```\n
[]