🚀 Contribution Technique | 🚀 Easy and Simple Implementation  | runs 100% Faster | cpp
Intuition\n1. we want to count the number of single occuring char in all the substrings .\n    eg : characters : cnt: - 3 size {h,t,e} occ single time  \n\n2. h
# Intuition\n1. we want to count the number of single occuring char in all the substrings .\n    eg : characters : cnt: - 3 size {h,t,e} occ single time  \n\n2. here we cant really generate all the sub array and cnt the number of single occuring char. so we will use **Contribution Technique** .\n\n3. So we count for all the characters in string that till how much the frq of char is one \n![Capture.PNG](https://assets.leetcode.com/users/images/ec8f4d83-fe44-46f0-90ea-d86f00398006_1692349048.2260525.png)\n\n4. lets cnt for a \n```\ncnt += (occ[i][j] - occ[i][j - 1]) * (occ[i][j + 1] - occ[i][j]);\n\n```\n![Capture.PNG](https://assets.leetcode.com/users/images/f540239c-92cd-413d-9e55-49c803c8301e_1692350862.932237.png)\n\n\n\n# Approach \n\n1. create a array of vector of 26 size then push -1 first \n2. then for each char from a to z push index so that we can count the subarray it is contributing \n3. then push n at last \n\n4. use the cnt += (occ[i][j] - occ[i][j - 1]) * (occ[i][j + 1] - occ[i][j]);  to calculate the number of subarray in which it contributes uniquely \n\n# Complexity\n- Time complexity:\n    O(26*n)\n\n# Code\n```\nclass Solution {\npublic:\n    int uniqueLetterString(string s) {\n        int n = s.size();\n        vector<int> occ[26];\n        for (int i = 0 ; i < 26; i++) {\n            occ[i].push_back(-1);\n        }\n        for (int i = 0 ; i < n ; i++) {\n            occ[s[i] - \'A\'].push_back(i);\n        }\n        for (int i = 0 ; i < 26 ; i++) {\n            occ[i].push_back(n);\n        }\n        int cnt = 0 ;\n        // (ontribution technique\n        // iterate on char and a_____a_____a\n        //                        x     y\n        //                  -1 0     i     n\n        //             cnt+=  (1*(i)) + (n-i*i)\n        for (int i = 0 ; i < 26 ; i++) {\n            for (int j = 1 ; j < (occ[i].size() - 1) ; j++) {\n                cnt += (occ[i][j] - occ[i][j - 1]) * (occ[i][j + 1] - occ[i][j]);\n            }\n        }\n        return cnt ; \n    }\n};\n```
['C++']