Ctrl K

Reach the Order by Reversals

Easy
You get two arrays of the same length: 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.
Example 1
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].

Example 2
goal=[2, 2, 4], tiles=[2, 4, 4] → False

tiles has one 2 but two are needed, and reversals never change the counts.

Example 3
goal=[9], tiles=[9] → True
Constraints
  • len(goal) == len(tiles)
  • 1 ≤ len(goal) ≤ 1000
  • 1 ≤ goal[i], tiles[i] ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsThe Candidate With Most Votes EasyDoes Any Value Repeat EasyThe Lost Ticket EasyValues in Both Lists EasyShared Values With Repeats Easy
loading Python…
Input
goal=[5, 1, 3, 3], tiles=[3, 5, 3, 1]
Expected
True

Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.