Number of Good Ways to Split a String LeetCode solution in C++
1class Solution {2public:3int numSplits(string s) {4int n = s.size();5vector<int> left(26, 0);6vector<int> right(26, 0);7int left_count = 0, right_count = 0;8int splits = 0;9for (auto &it : s) {10right[it - 'a']++;11if (right[it - 'a'] == 1) right_count++;12}13for (auto &it : s) {14left[it - 'a']++;15right[it - 'a']--;16if (left[it - 'a'] == 1) left_count++;17if (right[it - 'a'] == 0) right_count--;18if (left_count == right_count) splits++;19}20return splits;21}22};