Idiomatic Rust | 0ms
Time: $O(n)$ | $0$ms\nSpace: $O(1)$ | $2.10$mb\n\n\nimpl Solution {\n    pub fn are_similar(mat: Vec<Vec<i32>>, k: i32) -> bool {\n\n        #[derive(Copy, Clon
Time: $O(n)$ | $0$ms\nSpace: $O(1)$ | $2.10$mb\n\n```\nimpl Solution {\n    pub fn are_similar(mat: Vec<Vec<i32>>, k: i32) -> bool {\n\n        #[derive(Copy, Clone)]\n        enum Shift {\n            RIGHT, LEFT\n        }\n\n        let left_right_iter = [Shift::LEFT, Shift::RIGHT].into_iter().cycle();\n\n        let wrap_index_around = |x, limit| match x {\n            x if x >= limit => x % limit,\n            x if x < 0 => (limit + (x % limit)) % limit,\n            x => x,\n        } as usize;\n\n        let is_similar_when_shifted = |(row, direction): (Vec<i32>, Shift)| {\n            let offset = match direction {\n                Shift::RIGHT => k,\n                Shift::LEFT => -k,\n            };\n            let limit = row.len() as i32;\n            (0..limit)\n                .map(|x| (x as usize, wrap_index_around(x + offset, limit)))\n                .all(|(index1, index2)| row[index1] == row[index2])\n        };\n\n        mat.into_iter()\n            .zip(left_right_iter)\n            .all(is_similar_when_shifted)\n    }\n}\n```
['Rust']