C# DP Solution O(n) with explanation
I found this solution here to be most intuitive for me and created the C# version with some additional explanations that helped me understand this better: https
I found this solution here to be most intuitive for me and created the C# version with some additional explanations that helped me understand this better: https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/discuss/129021/O(N)-Java-Solution-DP-Clear-and-easy-to-Understand\n\nThe gist behind the DP here is\n* At each index i of the string, the solution will be the unique characters of all the substrings ending in current character s[i]\n* `contributions` helps keep track of how many substrings ending in s[i] have s[i] as a unique value\n* `lastPosition` is meant to keep track of when did the s[i] value last appear, this is so that we can calculate the appropriate `contributions` value for current s[i], since any substring that already previously had this character can no longer have this character as unique, hence `contributions[cIdx] = i + 1 - lastPosition[cIdx]`.\n* For the value inside of lastPosition, we use i + 1 since i starts at 0 for the first character and will collide with the default int array value which is also 0. Therefore, 0 in the int array `lastPosition` will mean that the value has not yet appeared in our iteration, while any value X that is greater than 0, will represent the Xth character in the string (aka the X-1 index character).\n\n\n```\npublic class Solution {\n    public int UniqueLetterString(string s) {\n        int[] contributions = new int[26];\n        int[] lastPosition = new int[26];\n        int result = 0;\n        \n        if (s == null || s.Length == 0) return result;\n        \n        int curr = 0;\n        for(int i = 0; i < s.Length; i++)\n        {\n            int cIdx = s[i] - \'A\';\n            curr -= contributions[cIdx];\n            contributions[cIdx] = i + 1 - lastPosition[cIdx];\n            curr += contributions[cIdx];\n            lastPosition[cIdx] = i + 1; // the reason why we do plus 1 is because 0 means hasn\'t shown up before\n            result += curr;\n        }\n        \n        return result;\n    }\n}\n```
[]