A few things I've been thinking about that may (not necessarily) help others into some insight about the exercise:
1 - O's on the sides are irrelevant.
2 - Intuitively, X's on the edges are the ones that should be swapped to the inside. This is in a greedy sense, but I'm not sure how greedy we're allowed to go yet.
3 - X's from the right side are more usefully moved to the inner left side (at least not just packed away into the nearest X).
At this point I had no idea where to continue from.
This exercise has actually made me more aware of the technique I use for solving logical problems. The difficult thing about optimization is that exhaustive search already solves the problem. You are left in an infinite? graph of logical connectives that you can walk through from multiple nodes. That's the closest thing I can describe of my process at the moment.
From the above points, I was able to use point (1) and point (2). (3) was more of an occasional observation, but wasn't strong enough. However what I was able to salvage out of it is that X's are more valuable on the inside rather than on the edges, which is intuitive.
From (1), I immediately trimmed O's on the sides.
A little explanation about (2). The whole problem relies on connectedness. X's on the sides can only extend other groups of X's. Hence they are more valuable on the inside between other groups.
From (2), it is possible to see that there are (maxSwaps + 1) ways to select X's to swap into the inside. Ie (0 X's from left, MaxSwaps from the right), (1 X from left, MaxSwaps-1 from the right) and so on till (MaxSwaps from left and none from the right).
Each of these (MaxSwaps+1) possibilities creates a new problem.
Of course, again, after we have removed MaxSwaps X's from the sides, we also need to trim the remaining O's.
To move on, we note one thing, our swapping operation has become a replace operation. Replace O's with X's. We wouldn't want to replace X's with X's, because that would always lead to poorer results.
Given the series of X's and O's in alternation, we'll do the following.
Start consecutively with a group of O's. Continue filling following O groups to its right. If there are remaining X's with no O's, then just add that to the sum of the spread. We get our subsubmax.
Our submax is for each of the configuration of left X's and right X's.
Our max is the max of all of these.