Easy and intuitive solution.
Intuition\n Describe your first thoughts on how to solve this problem. \nA simple brute rotation approach can be done since the constraints are low.\n\n# Approa
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nA simple brute rotation approach can be done since the constraints are low.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe code initializes a new 2D vector `final` with the same values as `mat`. Then, it iterates over each row of `mat`. If the row index is odd `(i % 2 != 0)`, it performs k rotations to the right by repeatedly moving the last element to the front. If the row index is even, it performs k rotations to the left by repeatedly moving the first element to the end.\n\nFinally, the code checks if `mat` is equal to `final` and returns the result.\n\n# Complexity\n- Time complexity:\n- O(n*n *k)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n- O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    bool areSimilar(vector<vector<int>>& mat, int k) {\n    vector<vector<int>> final = mat;\n\n    for (int i = 0; i < mat.size(); i++) {\n        if (i % 2 != 0) {\n            for (int j = 0; j < k; j++) {\n                int last = mat[i][mat[i].size()-1];\n                mat[i].pop_back();\n                mat[i].insert(mat[i].begin(), last);\n            }\n        } else {\n            for (int j = 0; j < k; j++) {\n                int first = mat[i][0];\n                mat[i].erase(mat[i].begin());\n                mat[i].push_back(first);\n            }\n        }\n    }\n    return mat==final;\n    }\n};\n```
['Math', 'Matrix', 'C++']