[C++] Single Pass
Complexity\n- Time complexity: O(mn)\n- Space complexity: O(1)\n\n# Code\n\nclass Solution {\npublic:\n    bool areSimilar(vector<vector<int>>& mat, int k) {\n 
# Complexity\n- Time complexity: $$O(mn)$$\n- Space complexity: $$O(1)$$\n\n# Code\n```\nclass Solution {\npublic:\n    bool areSimilar(vector<vector<int>>& mat, int k) {\n        int m = mat.size();\n        int n = mat[0].size();\n        k = k % n;\n        if (k == 0) {\n            return true;\n        }\n        for (int i = 0; i < m; i++) {\n            for (int j = 0; j < n; j++) {\n                if (i & 1) {\n                    if (mat[i][(j + k) % n] != mat[i][j]) {\n                        return false;\n                    }\n                } else {\n                    if (mat[i][(j - k + n) % n] != mat[i][j]) {\n                        return false;\n                    }\n                }\n            }\n        }\n        return true;\n    }\n};\n```
['Array', 'Math', 'Matrix', 'Simulation', 'C++']