x and y (so the string is x + y), the pieces are optionally swapped (giving y + x), and then each piece is shuffled the same way on its own.
You get two strings start and goal of equal length. Return true if some choice of cuts and swaps turns start into goal, and false otherwise.start="stone", goal="tones" → True
Cut "stone" into "s" and "tone" and swap them: "tone" + "s" = "tones". The pieces can then be left untouched.
start="abcd", goal="bdac" → False
The first cut gives "a"+"bcd", "ab"+"cd" or "abc"+"d". To reach "bdac", one piece must hold the same letters as a prefix or suffix of "bdac" of the same length ("b", "bd", "bda" or "c", "ac", "dac"). None of them match, so the answer is false.
start="z", goal="z" → True
start="stone", goal="tones"
True
Run checks the first 3 tests in your browser. Submit checks all 100 tests on the server, hidden ones included.