Trains the technique from
LeetCode 2840Check if Strings Can be Made Equal With Operations IIThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
Two display rails, left and right, each carry the same number of tiles. A tile is written as a lowercase letter, its colour. Seats on a rail are numbered from 0.
A fitter may repeat this move as often as they like, on either rail: pick two seats on the same rail whose numbers are both even or both odd, and swap the tiles sitting in them. Seats do not have to be next to each other.
Return true if the two rails can be made to show the same colours in the same seats, and false otherwise.
Example 1
Swapping the tiles in seats 0 and 2 of `left` turns it into "cbad", which is what `right` already shows.
Example 2
The even seats of `left` carry a, a and b, while the even seats of `right` carry a, b and b, and no permitted move changes either of those groups. So the rails cannot be made to agree.
Example 3
Seats 0 and 1 have different parity, so no permitted move touches this pair of tiles at all and the rails stay different.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def can_match_runs(left: str, right: str) -> bool:public boolean canMatchRuns(String left, String right)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.