You are given a string consisting of the letters x and y, such as xyxxxyxyy.
In addition, you have an operation called flip, which changes a single x to y or vice versa. Determine how many times you would need to apply this operation to ensure that all x‘s come before all y‘s.
In the preceding example, it suffices to flip the second and sixth characters, so you should return 2.
This problem asks for the minimum number of single-character flips needed to rearrange a string of x and y so that every x appears before every y. The key idea is to consider each possible split point: characters on the left side should be x, and characters on the right side should be y. For any split, the required flips equal the number of y's on the left plus the number of x's on the right. Scanning once with prefix/suffix counts yields an O(n) solution.