Reversal check
\n# Approach\nIdea is to simply reverse the k elements either to right or left depending on row and check if it is equal to the matrix row\n# Complexity\n- Time
\n# Approach\nIdea is to simply reverse the `k` elements either to right or left depending on row and check if it is equal to the matrix row\n# Complexity\n- Time complexity:$$O(n^2)$$\n- Space complexity:$$O(n)$$\n# Code\n```\nclass Solution {\npublic:\n    void rs(vector<int>& vec, int k) {\n        int size = vec.size();\n        k = k % size;\n        reverse(vec.begin(), vec.end());\n        reverse(vec.begin(), vec.begin() + k);\n        reverse(vec.begin() + k, vec.end());\n    }\n    void ls(vector<int>& vec, int k) {\n        int size = vec.size();\n        k = k % size;\n        reverse(vec.begin(), vec.end());\n        reverse(vec.begin(), vec.begin() + size - k);\n        reverse(vec.begin() + size - k, vec.end());\n    }\n    bool areSimilar(vector<vector<int>>& mat, int k) {\n        vector<vector<int>>cp=mat;\n        for(int i=0;i<mat.size();i++){\n            vector<int>tmp=mat[i];\n            if(i%2) rs(tmp,k);\n            else ls(tmp,k);\n            if(tmp!=mat[i]) return 0;\n        }\n        return 1;\n    }\n};\n```\n
['C++']