c = gcd(n, k) | Slice by slice comparison of [0, c) ranges | beats 100% time & mem
Intuition & Approach
Get k after complete cycles. If remaining cycles is 0, return true.
GCD of n & k will give the slices of a row which need to be equal for k
# Intuition & Approach

1. Get `k` after complete cycles. If remaining cycles is 0, return true.
2. GCD of `n` & `k` will give the slices of a row which need to be equal for `k` rotation to work.
3. I use two methods:
    1. First is to slice array in [0, gcd] ranges and compare them, this may be slow, as we are creating new slices of array for each slice of a row and for all rows.
    2. Second uses the same principle, but we compare element by element.

# Complexity

- Time complexity: $$O(m*n)$$
- Space complexity: $$O(1)$$

https://leetcode.com/submissions/detail/1534729723/

# Code
```cpp [C++ slices]
bool areSimilar(vector<vector<int>>& mat, int k) {
    int m = mat.size(), n = mat[0].size();
    k %= n; // after complete cycle
    if (k == 0)
        return true;
    for (int i = 0, c = gcd(n, k); i < m; i++) {
        vector<int> firstSlice =
            vector<int>(mat[i].begin(), mat[i].begin() + c);
        for (int j = 0; j + c < n; j += c)
            if (firstSlice != vector<int>(mat[i].begin() + j + c,
                                            mat[i].begin() + j + c + c))
                return false;
    }
    return true;
}
```
```cpp [C++ elements]
bool areSimilar(vector<vector<int>>& mat, int k) {
    int m = mat.size(), n = mat[0].size();
    k %= n; // after complete cycle
    if (k == 0)
        return true;
    for (int i = 0, c = gcd(n, k); i < m; i++)
        for (int j = 0; j + c < n; j++)
            if (mat[i][j] != mat[i][j + c])
                return false;
    return true;
}
```
['C++']