xyBalance: is every x followed by a y?
The string is "balanced" if every 'x' has a 'y' somewhere after it. You only need to check the last x: if some y comes after it, that y also comes after every earlier x. Step through xyBalance and watch lastIndexOf search from the right-hand end of the string.