You are given a string s.

A split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in sleft and sright is the same.

Return the number of good splits you can make in s.

&nbsp;
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").


&nbsp;
Constraints:


	1 &lt;= s.length &lt;= 105
	s consists of only lowercase English letters.


class Solution:
    def numSplits(self, s: str) -> int:
        one = set()
        two = set()
        dic = {}
        
        for i in s:
            dic[i] = dic.get(i, 0) + 1
            two.add(i)
        tot = 0
        
        for i in s:
            one.add(i)
            dic[i] -= 1
            if dic[i] == 0:
                two.remove(i)
            
            if len(one) == len(two):
                tot += 1
        return tot
class Solution {
    public int numSplits(String s) {
        int a[] = new int[26];
        int b[] = new int[26];
        int ds1=0,ds2=0;
        int count=0;
        for(int i=0;i<s.length();i++)
        {
            b[s.charAt(i)-97]++;
            if(b[s.charAt(i)-97] == 1)
                ds2++;
        }
        for(int i=0;i<s.length();i++)
        {
            a[s.charAt(i)-97]++;
            b[s.charAt(i)-97]--;
            if(b[s.charAt(i)-97] == 0)
                ds2--;
            if(a[s.charAt(i)-97] == 1)
                ds1++;
            if(ds1 == ds2)
                count++;
        }
        return count;
    }
}
class Solution {
public:
    int numSplits(string s) {
        int n=s.size();
        vector<int>left(26,0);
        vector<int>right(26,0);
        int left_count=0,right_count=0;
        int splits=0;
        for(auto &it:s){
            right[it-'a']++;
            if(right[it-'a']==1)right_count++;
        }
        for(auto &it:s){
            left[it-'a']++;
            right[it-'a']--;
            if(left[it-'a']==1)left_count++;
            if(right[it-'a']==0)right_count--;
            if(left_count==right_count)
                splits++;
        }
        return splits;
    }
};
var numSplits = function(s) {
        let n = s.length;
        let preFix = new Array(n) , suFix = new Array(n);
        let preSet = new Set();
        let suSet = new Set();

        for(let i=0; i<n ; i++){
            preSet.add(s[i]);
            suSet.add(s[n-1-i]);
            preFix[i]= preSet.size;
            suFix[n-1-i]= suSet.size;
        }

        let goodWays=0;

        for(let i=0; i<n-1; i++){
            if(preFix[i]===suFix[i+1]) goodWays++;
        }

        return goodWays;
};
Number of Good Ways to Split a String