Simple || In-depth explanation
For finding the unique characters in each sub string, we\'ll find the number of contributions of each character in the substring..\n\ni.e If a char \'A\' is pre
For finding the unique characters in each sub string, we\'ll find the number of contributions of each character in the substring..\n\ni.e If a char \'A\' is present in the string, then we\'ll find the contribution of \'A\', the number of substring in which \'A\' is present.\n\nlet\'s understand : \n\n![image.png](https://assets.leetcode.com/users/images/5023d5f8-1b3c-4637-9b7c-3aa04e07b486_1682478336.0947466.png)\n\n![image.png](https://assets.leetcode.com/users/images/aa5d5e88-e4ca-464e-8590-de032b015f23_1682478851.4251628.png)\n\n![image.png](https://assets.leetcode.com/users/images/b4684105-f76e-40b8-bf3a-50184ade3480_1682478864.7454462.png)\n\n![image.png](https://assets.leetcode.com/users/images/b2d77f3f-5307-4e56-baaa-1235d0124451_1682478904.5161598.png)\n\n![image.png](https://assets.leetcode.com/users/images/18bc13c3-ccf7-4e15-9cf3-370082c03878_1682478925.2353077.png)\n\n![image.png](https://assets.leetcode.com/users/images/174808c6-ff97-41c7-8e90-36a255ee0f4f_1682478938.0339274.png)\n\n![image.png](https://assets.leetcode.com/users/images/4cc19a3e-eaaa-4f2f-942a-8665d7cf0df3_1682478950.7331235.png)\n\n\n\n\n\n\n\n\n# Code\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; i++) hash[i].push_back(-1);\n// pushing -1 for all the 26 characters\n\n        for(int i = 0; i < n; i++) hash[s[i] - \'A\'].push_back(i);\n// storing the index of each character inside the map\n\n        for(int i = 0; i < 26; i++) hash[i].push_back(n);\n// pushing the last index for all the 26 characters\n\n// now calculating the count by taking the product of the left window and the right window\n\n        long long cnt = 0;\n        for(int i = 0; i < 26; i++){\n            for(int j = 1; j < hash[i].size()-1; j++){\n                cnt += (hash[i][j] - hash[i][j-1])*(hash[i][j+1] - hash[i][j]);\n            }\n        }\n\n        return cnt;\n    }\n};\n```
['C++']