Show problems as
Classic problem #1886EasyArrayMatrix

Determine Whether Matrix Can Be Obtained By Rotation

Real-world version: Stamping Plate Set Down A Quarter Turn At A Time
Tracked in this browser only
Read Determine Whether Matrix Can Be Obtained By Rotation on LeetCode(opens in a new tab)

The statement here is our own: the same inputs, outputs and technique.

A stamping press takes a square plate of n rows by n columns. plate[r][c] is 1 when the cell at row r, column c is raised and 0 when it is flat. The desired print is given the same way as wanted, also n by n.

An operator may lift the plate and set it back down turned a quarter turn clockwise, and may repeat that as many times as they like, including not at all. Nothing else is allowed: the plate is never flipped over and individual cells are never edited.

Return true when some number of quarter turns leaves the plate equal to wanted in every cell, and false otherwise.

Examples

Example 1

Input
plate = [[1, 0], [0, 0]], wanted = [[0, 1], [0, 0]]
Output
true

The single raised cell sits at row 0, column 0. One quarter turn clockwise carries it to row 0, column 1, which is exactly where `wanted` has its raised cell.

Example 2

Input
plate = [[1, 1, 0], [0, 0, 0], [0, 0, 0]], wanted = [[1, 0, 0], [1, 0, 0], [0, 0, 0]]
Output
false

The plate's two raised cells sit side by side along the top edge. The four orientations put that pair along the top edge, down the right edge, along the bottom edge and up the left edge, whereas `wanted` has its pair in the top half of the left column.

Example 3

Input
plate = [[1, 0, 0], [0, 1, 1], [0, 0, 0]], wanted = [[1, 0, 0], [0, 1, 1], [0, 0, 0]]
Output
true

The plate already equals `wanted`, and setting it down without turning it at all is allowed.

Constraints

  • 1 <= plate.length <= 10
  • 1 <= plate[i].length <= 10
  • 1 <= wanted.length <= 10
  • 1 <= wanted[i].length <= 10
  • plate.length == wanted.length
  • 0 <= plate[i][j] <= 1
  • 0 <= wanted[i][j] <= 1
  • Both plate and wanted are square: each has as many columns as it has rows.

The signature

The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.

Python
def can_rotate_to(plate: list[list[int]], wanted: list[list[int]]) -> bool:
Java
public boolean canRotateTo(int[][] plate, int[][] wanted)