LeetCode solutions

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

Read the problem on LeetCode View on GitHub

Python

Accepted on LeetCode — runtime 0ms, memory 17.3MB, accepted 2026-01-02.

python
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

Source