One sentence explanation. Hope this help you understand it quicker.
In one sentence: \ninstead of find the unique characters in every substring, go find all substring of every unique character.\n\n## what do you mean "every uniq
## In one sentence: \ninstead of find the unique characters in every substring, go find all substring of every unique character.\n\n## what do you mean "every unique character"? \nFor each character, find the longest substring, in which the character is unique. Then this longest substring has the left and right boundary of that unique character.\n\nexample: In "CABBD", the first \'B\' has a left boundary at 0 and right boundary at 3. \n\nWe can calculate the total number of substring for that \'B\', by (right boundary - i) * (i - left boundary + 1) = 3; test it yourself!\n\nFor all other characters, use the formula to calculate and sum them up to get the result.\n```\nclass Solution {\npublic:\n    int get_dict_index (char c) {\n        return (int)(c - \'A\');\n    }\n    int uniqueLetterString(string s) {\n        unordered_map<int, int> leftIndex;\n        unordered_map<int, int> rightIndex;\n        \n\t\t// get left boundary index as a dictionary\n        unordered_map<char, int> charToPrevIndex;\n        auto end = charToPrevIndex.end();\n        for (int i = 0; i < s.length(); ++i) {\n            if (charToPrevIndex.find(s[i]) != end) {\n                leftIndex[i] = charToPrevIndex[s[i]];\n            }\n            charToPrevIndex[s[i]] = i;\n        }\n        \n\t\t// get right boundary index as a dictionary\n        charToPrevIndex = unordered_map<char, int>();\n        for (int i = s.length() - 1; i >= 0; --i) {\n            if (charToPrevIndex.find(s[i]) != end) {\n                rightIndex[i] = charToPrevIndex[s[i]];\n            }\n            charToPrevIndex[s[i]] = i;\n        }\n        \n        int result = 0;\n        auto end_ = leftIndex.end();\n        for (int i = 0; i < s.length(); ++i) {\n            int left = leftIndex.find(i) == end_ ? 0 : leftIndex[i] + 1;\n            int right = rightIndex.find(i) == end_ ? s.length() : rightIndex[i];\n            result += (right - i) * (i - left + 1);\n        }\n        return result;\n    }\n};\n```
[]