FunctionRacerProblemsRace

Scrambled by Cuts

HardStringsPython, JavaScript, TypeScript, Java, C++

To scramble a string of two or more letters, cut it into two non-empty parts, choose whether the two parts trade places, and then scramble each part the same way. A single letter stays as it is.

Return True if scrambling text can give goal, otherwise False.

Example 1

text "tea"
goal "eat"
returns true

Cut tea into t and ea, and let the two parts trade places.

Example 2

text "abcd"
goal "bacd"
returns true

Cut into ab and cd. Scramble ab into ba, and leave cd as it is.

Example 3

text "abcd"
goal "bdac"
returns false

Wherever abcd is cut, the letters of its left part are not together at either end of bdac.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Strings problems