Turns to Match
Turning a grid a quarter turn clockwise makes its first column, read from bottom to top, the new first row, its second column the new second row, and so on, so a grid with R rows and C columns becomes one with C rows and R columns. a and b are grids given as lists of rows. Return the smallest number of clockwise quarter turns, 0, 1, 2 or 3, that turns a into exactly b, or -1 if none of them does. The two grids may have different shapes, and neither may be changed.
Example 1
One clockwise turn reads the first column (1, 3) from the bottom up as the row [3, 1] and the second column (2, 4) as [4, 2], which is b.
Example 2
One turn gives [[1], [2], [3]] and two turns give [[3, 2, 1]]; the third turn finally gives b.
Constraints
1 <= len(a), len(a[0]), len(b), len(b[0]) <= 6- within each grid every row has the same length
0 <= a[r][c], b[r][c] <= 9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Grids problems
- Turtle CommandsEasy
- Up and to the RightEasy
- Wireworld StepEasy
- Crush and FallMedium
- Four in a RowMedium
- Life-Like GenerationsMedium
- Minutes to BurnMedium
- Paths Around RocksMedium