2946. Matrix Similarity After Cyclic Shifts Easy

@problem@discussion
#Array#Math#Matrix#Simulation



1/**
2 * [2946] Matrix Similarity After Cyclic Shifts
3 *
4 * You are given an m x n integer matrix mat and an integer k. The matrix rows are 0-indexed.
5 * The following proccess happens k times:
6 * 
7 * 	Even-indexed rows (0, 2, 4, ...) are cyclically shifted to the left.
8 * 
9 * <img src="https://assets.leetcode.com/uploads/2024/05/19/lshift.jpg" style="width: 283px; height: 90px;" />
10 * 
11 * 	Odd-indexed rows (1, 3, 5, ...) are cyclically shifted to the right.
12 * 
13 * <img src="https://assets.leetcode.com/uploads/2024/05/19/rshift-stlone.jpg" style="width: 283px; height: 90px;" />
14 * Return true if the final modified matrix after k steps is identical to the original matrix, and false otherwise.
15 *  
16 * <strong class="example">Example 1:
17 * <div class="example-block">
18 * Input: <span class="example-io">mat = [[1,2,3],[4,5,6],[7,8,9]], k = 4</span>
19 * Output: <span class="example-io">false</span>
20 * Explanation:
21 * In each step left shift is applied to rows 0 and 2 (even indices), and right shift to row 1 (odd index).
22 * <img src="https://assets.leetcode.com/uploads/2024/05/19/t1-2.jpg" style="width: 857px; height: 150px;" />
23 * </div>
24 * <strong class="example">Example 2:
25 * <div class="example-block">
26 * Input: <span class="example-io">mat = [[1,2,1,2],[5,5,5,5],[6,3,6,3]], k = 2</span>
27 * Output: <span class="example-io">true</span>
28 * Explanation:
29 * <img src="https://assets.leetcode.com/uploads/2024/05/19/t1-3.jpg" style="width: 632px; height: 150px;" />
30 * </div>
31 * <strong class="example">Example 3:
32 * <div class="example-block">
33 * Input: <span class="example-io">mat = [[2,2],[2,2]], k = 3</span>
34 * Output: <span class="example-io">true</span>
35 * Explanation:
36 * As all the values are equal in the matrix, even after performing cyclic shifts the matrix will remain the same.
37 * </div>
38 *  
39 * Constraints:
40 * 
41 * 	1 <= mat.length <= 25
42 * 	1 <= mat[i].length <= 25
43 * 	1 <= mat[i][j] <= 25
44 * 	1 <= k <= 50
45 * 
46 */
47pub struct Solution {}
48
49// problem: https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts/
50// discuss: https://leetcode.com/problems/matrix-similarity-after-cyclic-shifts/discuss/?currentPage=1&orderBy=most_votes&query=
51
52// submission codes start here
53
54impl Solution {
55    pub fn are_similar(mat: Vec<Vec<i32>>, k: i32) -> bool {
56        false
57    }
58}
59
60// submission codes end
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_2946() {
68    }
69}
70


Back
© 2025 bowen.ge All Rights Reserved.