Java&JS&TS Solution (JW)
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\npublic boolean areSimilar(int[][] mat, int k) {\n    int m = mat.length;       // Number of rows\n    int n = mat[0].length;    // Number of columns\n    \n    // Normalize k to avoid unnecessary full cycles\n    k = k % n;\n    \n    for (int i = 0; i < m; i++) {\n        if (i % 2 == 0) { \n            // Even-indexed rows: Shift left\n            if (!isShiftedLeft(mat[i], k)) {\n                return false;\n            }\n        } else { \n            // Odd-indexed rows: Shift right\n            if (!isShiftedRight(mat[i], k)) {\n                return false;\n            }\n        }\n    }\n    return true;\n}\n\nprivate boolean isShiftedLeft(int[] row, int k) {\n    int n = row.length;\n    for (int j = 0; j < n; j++) {\n        // Check if the elements match after left shift\n        if (row[j] != row[(j + k) % n]) {\n            return false;\n        }\n    }\n    return true;\n}\n\nprivate boolean isShiftedRight(int[] row, int k) {\n    int n = row.length;\n    for (int j = 0; j < n; j++) {\n        // Check if the elements match after right shift\n        if (row[j] != row[(j - k + n) % n]) {\n            return false;\n        }\n    }\n    return true;\n}\n```\n```javascript []\nvar areSimilar = function(mat, k) {\n    const m = mat.length;       // Number of rows\n    const n = mat[0].length;    // Number of columns\n    \n    // Normalize k to avoid unnecessary full cycles\n    k = k % n;\n    \n    for (let i = 0; i < m; i++) {\n        if (i % 2 === 0) {\n            // Even-indexed rows: Shift left\n            if (!isShiftedLeft(mat[i], k, n)) {\n                return false;\n            }\n        } else {\n            // Odd-indexed rows: Shift right\n            if (!isShiftedRight(mat[i], k, n)) {\n                return false;\n            }\n        }\n    }\n    return true;\n};\n\nfunction isShiftedLeft(row, k, n) {\n    for (let j = 0; j < n; j++) {\n        if (row[j] !== row[(j + k) % n]) {\n            return false;\n        }\n    }\n    return true;\n}\n\nfunction isShiftedRight(row, k, n) {\n    for (let j = 0; j < n; j++) {\n        if (row[j] !== row[(j - k + n) % n]) {\n            return false;\n        }\n    }\n    return true;\n}\n```\n```typescript []\nfunction areSimilar(mat: number[][], k: number): boolean {\n    const m: number = mat.length;       // Number of rows\n    const n: number = mat[0].length;    // Number of columns\n    \n    // Normalize k to avoid unnecessary full cycles\n    k = k % n;\n\n    for (let i = 0; i < m; i++) {\n        if (i % 2 === 0) {\n            // Even-indexed rows: Shift left\n            if (!isShiftedLeft(mat[i], k, n)) {\n                return false;\n            }\n        } else {\n            // Odd-indexed rows: Shift right\n            if (!isShiftedRight(mat[i], k, n)) {\n                return false;\n            }\n        }\n    }\n    return true;\n};\n\nfunction isShiftedLeft(row: number[], k: number, n: number): boolean {\n    for (let j = 0; j < n; j++) {\n        if (row[j] !== row[(j + k) % n]) {\n            return false;\n        }\n    }\n    return true;\n}\n\nfunction isShiftedRight(row: number[], k: number, n: number): boolean {\n    for (let j = 0; j < n; j++) {\n        if (row[j] !== row[(j - k + n) % n]) {\n            return false;\n        }\n    }\n    return true;\n}\n```
['Array', 'Math', 'Java', 'TypeScript', 'JavaScript']