Class Solution
-
- All Implemented Interfaces:
public final class Solution2946 - Matrix Similarity After Cyclic Shifts.
Easy
You are given a 0-indexed
m x ninteger matrixmatand an integerk. You have to cyclically right shift odd indexed rowsktimes and cyclically left shift even indexed rowsktimes.Return
trueif the initial and final matrix are exactly the same andfalseotherwise.Example 1:
Input: mat = \[\[1,2,1,2],5,5,5,5,6,3,6,3], k = 2
Output: true
Explanation: Initially, the matrix looks like the first figure. Second figure represents the state of the matrix after one right and left cyclic shifts to even and odd indexed rows. Third figure is the final state of the matrix after two cyclic shifts which is similar to the initial matrix. Therefore, return true.
Example 2:
Input: mat = \[\[2,2],2,2], k = 3
Output: true
Explanation: As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same. Therefeore, we return true.
Example 3:
Input: mat = \[\[1,2]], k = 1
Output: false
Explanation: After one cyclic shift, mat = \[\[2,1]] which is not equal to the initial matrix. Therefore we return false.
Constraints:
1 <= mat.length <= 251 <= mat[i].length <= 251 <= mat[i][j] <= 251 <= k <= 50