Determine Whether Matrix Can Be Obtained By Rotation
Real-world version: Stamping Plate Set Down A Quarter Turn At A TimeThe 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.
def can_rotate_to(plate: list[list[int]], wanted: list[list[int]]) -> bool:public boolean canRotateTo(int[][] plate, int[][] wanted)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 13 test cases: 13 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's