goal is the order of tiles you want and tiles is the current one. In one move you pick any contiguous non-empty segment of tiles and reverse it. You may make as many moves as you like.
Return True if tiles can be turned into goal this way, and False otherwise.goal=[5, 1, 3, 3], tiles=[3, 5, 3, 1] → True
Reverse [3, 5] to get [5, 3, 3, 1], then reverse [3, 3, 1] to get [5, 1, 3, 3].
goal=[2, 2, 4], tiles=[2, 4, 4] → False
tiles has one 2 but two are needed, and reversals never change the counts.
goal=[9], tiles=[9] → True
goal=[5, 1, 3, 3], tiles=[3, 5, 3, 1]
True
Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.