3643. Flip Square Submatrix Vertically Easy

@problem@discussion
#Array#Two Pointers#Matrix



1/**
2 * [3643] Flip Square Submatrix Vertically
3 *
4 * You are given an m x n integer matrix grid, and three integers x, y, and k.
5 * The integers x and y represent the row and column indices of the top-left corner of a square submatrix and the integer k represents the size (side length) of the square submatrix.
6 * Your task is to flip the submatrix by reversing the order of its rows vertically.
7 * Return the updated matrix.
8 *  
9 * <strong class="example">Example 1:
10 * <img alt="" src="https://assets.leetcode.com/uploads/2025/07/20/gridexmdrawio.png" style="width: 300px; height: 116px;" />
11 * <div class="example-block">
12 * Input: <span class="example-io">grid = </span>[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]]<span class="example-io">, x = 1, y = 0, k = 3</span>
13 * Output: <span class="example-io">[[1,2,3,4],[13,14,15,8],[9,10,11,12],[5,6,7,16]]</span>
14 * Explanation:
15 * The diagram above shows the grid before and after the transformation.
16 * </div>
17 * <strong class="example">Example 2:
18 * <img alt="" src="https://assets.leetcode.com/uploads/2025/07/20/gridexm2drawio.png" style="width: 350px; height: 68px;" />​​​​​​​
19 * <div class="example-block">
20 * Input: <span class="example-io">grid = [[3,4,2,3],[2,3,4,2]], x = 0, y = 2, k = 2</span>
21 * Output: <span class="example-io">[[3,4,4,2],[2,3,2,3]]</span>
22 * Explanation:
23 * The diagram above shows the grid before and after the transformation.
24 * </div>
25 *  
26 * Constraints:
27 * 
28 * 	m == grid.length
29 * 	n == grid[i].length
30 * 	1 <= m, n <= 50
31 * 	1 <= grid[i][j] <= 100
32 * 	0 <= x < m
33 * 	0 <= y < n
34 * 	1 <= k <= min(m - x, n - y)
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/flip-square-submatrix-vertically/
40// discuss: https://leetcode.com/problems/flip-square-submatrix-vertically/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn reverse_submatrix(grid: Vec<Vec<i32>>, x: i32, y: i32, k: i32) -> Vec<Vec<i32>> {
46        vec![]
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_3643() {
58    }
59}
60

Back
© 2026 bowen.ge All Rights Reserved.