Simple Application of Rotate Array problem with little adjustment.
Intuition\n Describe your first thoughts on how to solve this problem. \nThe Thoughts were to use a reverse function to rotate the individual row of a matrix.\n
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe Thoughts were to use a reverse function to rotate the individual row of a matrix.\nThe main idea was to treat each row of the Matrix as a single row array and then apply rotations on it as per requirement of even and odd row.\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTo address the rotation of odd-indexed rows, we can utilize the modulus operator to shift each element to the next location using the formula **( \uD835\uDC57+\uD835\uDC58 ) % \uD835\uDC50**. \nj=index to traverse the columns\nc = total number of columns.\n\nThis effectively allows us to achieve right shifting for odd-indexed rows with ease.\nThe primary challenge lies in performing left shifts for even-indexed rows. For this, we employ the reverse function three times. This problem is an application of the Rotate Array Problem (Problem number 189).\n\nAlso I have used Two-pointers approach in reverse array Function.\n\n# Complexity\n- Time complexity: **O(r\u22C5c)**\nr = Number of rows.\nc = Number of columns.\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: **O(r\u22C5c)**\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public boolean areSimilar(int[][] mat, int k) {\n        int r = mat.length;\n        int c = mat[0].length;\n        k=k%c;\n        if(k==0)\n        {\n            return true;\n        }\n        // return false;\n        int[][] res = new int[r][c];\n\n        for(int i=1;i<r;)\n        {\n           for(int j=0;j<c;j++)\n           {\n                res[i][(j+k)%c] = mat[i][j];\n           }\n           i=i+2;\n        }\n        for(int i=0;i<r;)\n        {\n            int[] arr = new int[c];\n            for(int j=0;j<c;j++)\n            {\n                arr[j] = mat[i][j];\n            }\n            arr = reverse(arr,0,k-1);\n            arr = reverse(arr,k,c-1);\n            arr = reverse(arr,0,c-1);\n            for(int j=0;j<c;j++)\n            {\n                res[i][j] = arr[j];\n            }\n            i=i+2;\n        }\n\n        for(int i=0;i<r;i++)\n        {\n            for(int j=0;j<c;j++)\n            {\n                if(mat[i][j]!=res[i][j])\n                {\n                    return false;\n                }\n                // System.out.println(res[i][j]);\n            }\n        }\n        return true;\n        \n    }\n    public int[] reverse(int[] arr,int st, int end)\n    {\n        while(st<=end)\n        {\n            int temp = arr[st];\n            arr[st] = arr[end];\n            arr[end]=temp;\n            st++;\n            end--;\n        }\n        return arr;\n    }\n}\n```
['Array', 'Two Pointers', 'Matrix', 'Java']