3215. Matrix Similarity After Cyclic Shifts
My accepted Python solution to LeetCode problem 3215, Matrix Similarity After Cyclic Shifts, running in 0ms.
- Difficulty: Easy
- Python
- Runtime 0ms
- Memory 17.3MB
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
Python
Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2026-01-02.
class Solution:
def areSimilar(self, mat: List[List[int]], k: int) -> bool:
n = len(mat[0])
k = k % n
if k == 0:
return True
for row in mat:
for i in range(n):
if row[i] != row[(i + k) % n]:
return False
return True