Java solution
Approach
Cyclic Shifting Intuition:

For even-indexed rows, the elements are cyclically shifted to the left. The function even() validates if, after 𝑘 left shif
# Approach
<!-- Describe your first thoughts on how to solve this problem. -->
1. Cyclic Shifting Intuition:

* For even-indexed rows, the elements are cyclically shifted to the left. The function even() validates if, after 𝑘 left shifts, the row elements match their original positions.
* For odd-indexed rows, the elements are cyclically shifted to the right. The function odd() checks if the right-shifted elements align with their initial positions.
2. Key Observations:

* Shifting k times on a row is equivalent to shifting 𝑘
% length of the row k%length of the row times. This prevents unnecessary iterations.
* For both left and right shifts, modular arithmetic helps calculate the indices of elements after the shifts.
3. Validation Logic:

* For left shifts (even()), elements before length−𝑘
length−k should align with the elements starting from index 𝑘
, and the remaining elements should wrap around.
* For right shifts (odd()), elements in the last 𝑘 positions should align with the start of the row, and the rest should wrap around.
4. Row-wise Verification:

* Each row is checked based on its index (even or odd) using the respective helper function (even() or odd()). If any row fails the check, the matrix cannot match the original.


<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```java []
class Solution {
    boolean even (int[] arr , int k){
        for(int i=0;i<arr.length-k;i++){
            if(arr[i]!=arr[i+k]){
                return false;
            }
        }
         for(int i=arr.length-k;i<arr.length;i++){
            if(arr[i]!=arr[i-(arr.length-k)]){
                return false;
            }
         }
        return true;
    }
    boolean odd(int[] arr , int k){
        for(int i=0;i<k;i++){
            if(arr[i]!=arr[arr.length-k+i]){
                return false;
            }
        }
        for(int i=k;i<arr.length;i++){
            if(arr[i]!=arr[i-k]){
                return false;
            }
        }
        return true;
    }
    public boolean areSimilar(int[][] mat, int k) {
        int i=0;
        k=k % mat[0].length;
       
        for(int[] arr : mat){
            if(i%2==0){
                if(!even(arr, k)){
                    return false;
                }
            }
            else{
                 if(!odd(arr, k)){
                    return false;
                 }
            }
            i++;
        }
        return true;
    }
}
```
['Java']