Balance a Two-Letter String with at Most Two Cuts
Problem statement
A string s contains only a and b, with an even total count of each letter. Split it into contiguous pieces using at most two internal cuts, then give whole pieces to two recipients so each receives exactly half of all a characters and half of all b characters.
Return one cut boundary [c] when prefix s[0:c] is balanced against the suffix. Otherwise return two boundaries [l, r] when the middle piece s[l:r] contains both half-counts and the outer pieces go to the other recipient. Prefer one cut; within the chosen cut count, return lexicographically smallest boundaries. Return an empty array if no split exists.
Function
findBalanceCuts(s: String) → int[]Examples
Example 1
s = "abba"return = [2]Case 1 exercises the documented deterministic contract.
Example 2
s = "aabb"return = [1,3]Case 2 exercises the documented deterministic contract.
Example 3
s = "aaaabbbb"return = [2,6]Case 3 exercises the documented deterministic contract.
Constraints
2 <= s.length <= 400.scontains onlyaandb.- The total count of each letter is even.
- Every cut is internal, so both recipients receive at least one character.