Visualization of Solution
I hope you find this visualization helpful in understanding the solution. Credit goes to @akliang for the code. \n\n\n    public int uniqueLetterString(String s
I hope you find this visualization helpful in understanding the solution. Credit goes to @akliang for the code. \n\n\n    public int uniqueLetterString(String s) {\n        int[] contribution = new int[26];\n        int[] last_known_position = new int[26];\n        int curr = 0;\n        int sum = 0;\n        \n        int idx = 1;\n        for(int i = 0; i<s.length(); i++){\n            int pos = s.charAt(i) - \'A\';  \n            curr -= contribution[pos];    \n            contribution[pos] = idx - (last_known_position[pos]);   \n            curr+= contribution[pos];    \n            last_known_position[pos] = idx;\n            sum+= curr;\n            idx++;\n        }\n        return sum;\n    }\n\n![image](https://assets.leetcode.com/users/images/caf00ce9-14dd-4fc9-9e50-eace0b79c2bf_1661539544.2828.jpeg)\n![image](https://assets.leetcode.com/users/images/d0a53c6f-df7a-4d70-902e-7588c7df787d_1661539563.8936622.jpeg)\n![image](https://assets.leetcode.com/users/images/71a14eb8-18e4-4fb0-9ea9-cec594ba1233_1661539574.0419872.jpeg)\n
[]