0ms and 100 beats code in cpp.
Intuitionshift on basis of rows of matrix for k times.ApproachShift the rows based on row even or odd cretria for k times and check it is identical to matrix wi
# Intuition
shift on basis of rows of matrix for k times.

# Approach
Shift the rows based on row even or odd cretria for k times and check it is identical to matrix without shifts.

# Complexity
- Time complexity:
O(n^3).

- Space complexity:
O(n*m).

# Code
```cpp []
class Solution {
public:
    bool areSimilar(vector<vector<int>>& mat, int k) {
        vector<vector<int>> original(mat.size(), vector<int>(mat[0].size(), 0));
        original = mat;
        for(int l = 0; l < k; l++) {
            for(int i = 0; i < mat.size(); i++) {
                if(i % 2 == 0) {
                    int first = mat[i][0];
                    for(int j = 1; j < mat[i].size(); j++) {
                        int temp = mat[i][j-1];
                        mat[i][j-1] = mat[i][j];
                        mat[i][j] = temp;
                    }
                    mat[i][mat[i].size() - 1] = first;
                } else {
                    int last = mat[i][mat[i].size() - 1];
                    for(int j = mat[i].size() - 2; j >= 0; j--) {
                        int temp = mat[i][j + 1];
                        mat[i][j + 1] = mat[i][j];
                        mat[i][j] = temp;
                    }
                    mat[i][0] = last;
                }
            }
        }
        if(mat == original) return true;
        return false;
    }
};

```
['C++']