Easy C++
Approach\n- Calculate new start positions of row\n- Use a flag to keep track if we are on an even or odd row\n- Using the new start positions of each row, compa
# Approach\n- Calculate new start positions of row\n- Use a flag to keep track if we are on an even or odd row\n- Using the new start positions of each row, compare it with the original matrix\n\nMy first solution, please thumbs up if you found it helpful :)\n\n# Complexity\n- Time complexity: $$O(nRows \\times nCols)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$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    int n = mat[0].size();\n    // new start idx for odd rows\n    int oddStart = k % n;\n    // new start idx for even rows\n    int evenStart = oddStart == 0 ? 0 : n - oddStart;\n    // set odd flag to true as first row is taken as 1\n    bool odd = true;\n\n    for (vector<int> row : mat) {\n      int start = odd ? oddStart : evenStart;\n      for (int i = 0; i < row.size(); i++) {\n        if (row[i] != row[start]) {\n          return false;\n        }\n        // start mod n to loop back\n        start = (start + 1) % n;\n      }\n      odd = !odd;\n    }\n    return true;\n  }\n};\n\n```
['C++']