All problems
0746EasyArrayMatrix

Stamping Plate Set Down A Quarter Turn At A Time

Tracked in this browser only
Write code

Trains the technique from

LeetCode 1886Determine Whether Matrix Can Be Obtained By Rotation

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

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