human
I found an interesting problem on https://leetcode.com/problems/number-of-good-ways-to-split-a-string/:
You are given a string s, a split is called good if you can split s into 2 non-empty strings p and q where its concatenation is equal to s and the number of distinct letters in p and q are the same.
Return the number of good splits you can make in s.
 
Example 1:
Input: s = "aacaba"
Output: 2
Explanation: There are 5 ways to split "aacaba" and 2 of them are good. 
("a", "acaba") Left string and right string contains 1 and 3 different letters respectively.
("aa", "caba") Left string and right string contains 1 and 3 different letters respectively.
("aac", "aba") Left string and right string contains 2 and 2 different letters respectively (good split).
("aaca", "ba") Left string and right string contains 2 and 2 different letters respectively (good split).
("aacab", "a") Left string and right string contains 3 and 1 different letters respectively.

Example 2:
Input: s = "abcd"
Output: 1
Explanation: Split the string as follows ("ab", "cd").

Example 3:
Input: s = "aaaaa"
Output: 4
Explanation: All possible splits are good.
Example 4:
Input: s = "acbadbaada"
Output: 2

 
Constraints:

s contains only lowercase English letters.
1 <= s.length <= 10^5

I tried it in Python, but could not do it. Can you solve it?

Write me a the Python code you requested?
assistant
#Here is the Python code you requested.

class Solution:
    def numSplits(self, s: str) -> int:
        # stores 
        unique_chars = {}
        for i, char in enumerate(s):
            if char in unique_chars:
                first, last = unique_chars[char]
                unique_chars[char] = (first, i)
            else:
                unique_chars[char] = (i, i)
        n_unique_chars = len(list(unique_chars.keys()))
        events = []
        for start, end in list(unique_chars.values()):
            events.append((start, 1))
            events.append((end, -1))
        events.sort(key=lambda x: x[0])
        
        left_num = 0
        right_num = n_unique_chars
        total = 0
        start_good = None
        #print(events)
        for i, event_type in events:
            #print(i, event_type, left_num, right_num)
            if start_good is not None:
                return i - start_good
            if event_type == 1:
                left_num += 1
            else:
                right_num -= 1
            if left_num == right_num:
                start_good = i