O(N) O(N) Two Pass | HashMap | Intuition | Ccontribution| Java
```\nclass Solution {\n    public int uniqueLetterString(String s) {\n        //For s[i], the contribution it makes to the answer is (l) * (r)\n        //l,r : 
```\nclass Solution {\n    public int uniqueLetterString(String s) {\n        //For s[i], the contribution it makes to the answer is (l) * (r)\n        //l,r : the distance from the index i to the first left/right element that is equal to s[i]\n        //Because a character only contributes to the answer if it is the unique character in the array\n        //So the problem becomes to calculate l and r for each s[i]\n        //We can iterate the array, and use an array to store the last index for 26 characters\n        int n = s.length();\n        int[] lastIndex = new int[26];\n        Arrays.fill(lastIndex, -1);\n        int[] f = new int[n];\n        for (int i = 0; i < n; i++) {\n            int c = (s.charAt(i) - \'A\') ;\n            f[i] = i - lastIndex[c];\n            lastIndex[c] = i;\n        }\n        Arrays.fill(lastIndex, n);\n        int res = 0;\n        for (int i = n - 1; i >= 0; i--) {\n            int c = (s.charAt(i) - \'A\') ;\n            f[i] = (lastIndex[c] - i) * f[i];\n            res += f[i];\n            lastIndex[c] = i;\n        }\n        return res;\n    }\n}
['Java']