2025-08-22 11:28:05 +0000 UTC
Matrix Similarity After Cyclic Shifts
Categories:
Links
Code
class Solution:
def areSimilar(self, mat: List[List[int]], k: int) -> bool:
cols = len(mat[0])
for row in range(len(mat)):
is_even = row % 2 == 0
for col in range(cols):
if is_even:
new_col = (col - k + cols) % cols
else:
new_col = (col + k) % cols
if mat[row][col] != mat[row][new_col]:
return False
return True