Loading...
Loading...
You are given a string s made of the characters 'a' and 'b'. The number of 'a' characters in s is even, and so is the number of 'b' characters.
Consider cutting s at up to two positions. The cuts split s into up to three consecutive pieces, and each piece is given to one of two people. A person may receive more than one piece. A split is fair if both people end up with the same number of 'a' characters and the same number of 'b' characters.
Return the smallest start index of a block of len(s) / 2 consecutive characters that one person receives in full in some fair split.
You can assume at least one such block exists.
Input: s = "abab"
Output: 0
Explanation: A single cut in the middle gives "ab" to one person and "ab" to the other. Both have one 'a' and one 'b'. The first person holds the block starting at index 0.
Input: s = "aabb"
Output: 1
Explanation: Cutting after index 0 and after index 2 gives "ab" (indices 1 and 2) to one person and "a" + "b" (indices 0 and 3) to the other. Both have one 'a' and one 'b'. No block starting at index 0 works, because "aa" has two 'a' characters.
s.length ≤105s[i] is 'a' or 'b''a' characters and the number of 'b' characters are both even