Open this Post bro 🕶️ | C++ | Easiest Solution | Each Line Explained
\nclass Solution {\npublic:\n    bool areSimilar(vector<vector<int>>& mat, int k) {\n        int m = mat.size();\n        int n = mat[0].size();\n        \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        \n        // For each row, calculate the effective shift and check if the matrix is similar to itself.\n        for (int i = 0; i < m; ++i) {\n            int effectiveShift = k % n; // Effective shift amount after k shifts\n            \n            // Calculate shift direction\n            if (i % 2 == 0) { // Even-indexed rows are shifted to the left\n                effectiveShift = (n - effectiveShift) % n;\n            } // Odd-indexed rows are shifted to the right, which matches effectiveShift directly\n            \n            // Check if the row is in its original position after the shift\n            for (int j = 0; j < n; ++j) {\n                // Calculate the new index after the shift\n                int newIdx = (j + effectiveShift) % n;\n                if (mat[i][j] != mat[i][newIdx]) {\n                    return false; // If any element does not match, return false\n                }\n            }\n        }\n        \n        return true; // If all elements match after shifts, return true\n    }\n};\n\n```
['Matrix']