C++ Easy Solution | Intuitive | Comments Explained
Intuition\nCheck the elements before and after the operations.\n\n# Approach\nPerform the operations and find new elements for position in matrix. Check if curr
# Intuition\nCheck the elements before and after the operations.\n\n# Approach\nPerform the operations and find new elements for position in matrix. Check if current and new elements match. \n\n# Complexity\n- Time complexity: $$O(n*n)$$\n\n- Space complexity: $$O(1)$$ \n\n# Code\n```\nclass Solution {\npublic:\n    bool areSimilar(vector<vector<int>>& grid, int k) {\n        int n = grid.size(), m = grid[0].size(), newCol=0;\n\n        // Operations\n        for(int row=0; row<n; row++){\n            for(int col=0; col<m; col++){\n                //Even - Left Shift\n                if(!row&2) newCol = (abs(col- k))%m;\n                else newCol = (col + k)%m;\n\n                // Check elements\n                if(grid[row][newCol] != grid[row][col]) return false;\n            }\n        }\n        return true;\n    }\n};\n```
['C++']