The Determine Whether Matrix Can Be Obtained By Rotation coding problem asks you to check if a square matrix mat can be transformed into another matrix target by rotating it 90 degrees clockwise, zero to three times.
This is a popular question at Microsoft and Meta to test your matrix manipulation skills. Rotating a matrix 2D array involves swapping elements in a specific pattern. It evaluations whether you can perform in-place rotations or whether you can correctly identify the coordinate transformations for a 90-degree turn.
This problem uses Matrix Rotation and Simulation. There are two ways to check:
mat 90 degrees, compare with target. Repeat up to 4 times.mat[i][j] matches target in any of the four rotation positions:
Matrix mat:
0 1
1 1
Target target:
1 0
1 1
mat target.mat[0][0] o mat[0][1], etc.
mat:1 0
1 1
mat == target. Result: true.true.The most concise way to rotate a matrix 90 degrees is to Transpose it (swap arr[i][j] with arr[j][i]) and then Reverse each row. This two-step process is much easier to code than direct coordinate swapping.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Richest Customer Wealth | Easy | Solve | |
| Check if Matrix Is X-Matrix | Easy | Solve | |
| Largest Local Values in a Matrix | Easy | Solve | |
| Matrix Diagonal Sum | Easy | Solve | |
| Image Smoother | Easy | Solve |