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 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.
Example 1
Input
s = "aacaba"Output
2There are 5 ways to split
"aacaba", and the splits ("aac", "aba") and ("aaca", "ba") have the same number of distinct letters on both sides.Example 2
Input
s = "abcd"Output
1Splitting the string as
("ab", "cd") gives two distinct letters on each side.Constraints
- 1 <= s.length <= 10^5
- s consists of only lowercase English letters.