Determine Whether Matrix Can Be Obtained By Rotation

EasyMatrixsimulation

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You are given two n x n binary matrices mat and target. Return true if rotating mat by 90 degrees some number of times (0, 1, 2 or 3 times) makes it identical to target, and false otherwise. Only whole-matrix rotations are allowed; no reflections.

Examples

Input: mat = [[0,1],[1,0]], target = [[1,0],[0,1]]
Output: true
One 90-degree rotation of mat equals target.
Input: mat = [[0,1],[1,1]], target = [[1,0],[0,1]]
Output: false
mat has three 1s and target has two, so no rotation can match.
Input: mat = [[0,0,0],[0,1,0],[1,1,1]], target = [[1,1,1],[0,1,0],[0,0,0]]
Output: true
Rotating twice (180 degrees) turns the bottom row into the top row.

Constraints

  • n == mat.length == target.length
  • n == mat[i].length == target[i].length
  • 1 <= n <= 10
  • `mat[i][j]` and `target[i][j]` are 0 or 1.

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More simulation problems