[Python3] Dynamic Programming + Hash Table - Simple Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n- This is a harder version of 2262. Total Appeal of A String. Thus, do it first before 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n- This is a harder version of [2262. Total Appeal of A String](https://leetcode.com/problems/total-appeal-of-a-string/description/). Thus, do it first before going into this problem.\n- Problem asking about substring or subarray, we should always think about going from left to right and finding number of substring ending at current index that satisfies specific condition.\n- The number of substring or subarray satisfies condition will equal to `current index` - `first_index_from_left`, with `first_index_from_left` is the first index from the left that make `string[first_index_from_left ... current_index]` statifies the requirement condition.\n- At current index, we find the difference between the most recent meet and the second most recent meet of each character. It is the number of existing of that character in a substring ending at current index.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity: $$O(N * 26)$$ ~ $$O(N)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(26 * 2)$$ ~ $$O(1)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def uniqueLetterString(self, s: str) -> int:\n        last_exists = collections.defaultdict(lambda: [-1, -1])\n        res = 0\n        for i, c in enumerate(s):\n            last_exists[c][0], last_exists[c][1] = i, last_exists[c][0]\n            for _, exists in last_exists.items(): res += exists[0] - exists[1]\n        return res\n```
['Hash Table', 'String', 'Dynamic Programming', 'Python3']