Easy to understand ! Clean Solution ! Java
This solution is inspired by the explanation mentioned in this post by @zpdbbrx\n\nPlease refer to that post for complete clarity of the problem and this soluti
This solution is inspired by the explanation mentioned in [this](https://leetcode.com/problems/count-unique-characters-of-all-substrings-of-a-given-string/discuss/1505263/Single-pass-O(n)-time-and-O(1)-space-solution-with-detailed-explanation) post by [@zpdbbrx](https://leetcode.com/zpdbbrx/)\n\nPlease refer to that post for complete clarity of the problem and this solution.\n\n```\n public int uniqueLetterString(String password) {\n        \n        int sum = 0, curr = 0, n = password.length();\n        \n        int[] last = new int[26];\n        int[] prev = new int[26];\n        \n        Arrays.fill(last,-1);\n        Arrays.fill(prev,-1);\n        \n        char[] chars = password.toCharArray();\n        for(int i=0;i<n;i++) {\n            char c = chars[i];\n            // curr = curr + q - r + 1 , where\n            // q = i - lastIndex - 1\n            // r  = lastIndex - previndex\n            curr += (i - last[c-65] - 1) - (last[c-65] - prev[c-65]) + 1;\n            sum += curr;\n\t\t\t\n\t\t\t//update indices\n\t        prev[c-65] = last[c-65];\n            last[c-65] = i;\n        }\n        \n        return sum;\n    }\n\n```\n
['Dynamic Programming', 'Java']