Ctrl K

Match After Turning

Easy
A square stencil tile grid of size n × n lies on a table: each cell is either cut out (1) or solid (0). There is also a pattern goal of the same size. You may turn the tile on the table by 90° as many times as you like (flipping it over is not allowed). Return True if some number of turns (possibly zero) makes the tile match the pattern cell for cell, and False otherwise.
Example 1
grid=[[1, 1], [0, 0]], goal=[[0, 1], [0, 1]] → True

A 90° clockwise turn moves the top row into the right column, which gives goal.

Example 2
grid=[[1, 0], [0, 0]], goal=[[0, 1], [1, 0]] → False

grid has a single 1 while goal has two, so no turn can fix that.

Example 3
grid=[[0, 0, 1], [0, 1, 0], [0, 0, 0]], goal=[[0, 0, 0], [0, 1, 0], [1, 0, 0]] → True

A 180° turn moves the corner cell from the top right to the bottom left.

Constraints
  • 1 ≤ n ≤ 10
  • grid and goal are both n × n
  • Every cell is 0 or 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCrossword That Reads Both Ways EasyIsland Coastline Length EasyRepack the Tray EasyBlur the Pixels EasyPaint Bucket Tool Easy
loading Python…
Input
grid=[[1, 1], [0, 0]], goal=[[0, 1], [0, 1]]
Expected
True

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