2684. Maximum Number of Moves in a Grid Medium

@problem@discussion
#Array#Dynamic Programming#Matrix



1/**
2 * [2684] Maximum Number of Moves in a Grid
3 *
4 * You are given a 0-indexed m x n matrix grid consisting of positive integers.
5 * You can start at any cell in the first column of the matrix, and traverse the grid in the following way:
6 * 
7 * 	From a cell (row, col), you can move to any of the cells: (row - 1, col + 1), (row, col + 1) and (row + 1, col + 1) such that the value of the cell you move to, should be strictly bigger than the value of the current cell.
8 * 
9 * Return the maximum number of moves that you can perform.
10 *  
11 * <strong class="example">Example 1:
12 * <img alt="" src="https://assets.leetcode.com/uploads/2023/04/11/yetgriddrawio-10.png" style="width: 201px; height: 201px;" />
13 * Input: grid = [[2,4,3,5],[5,4,9,3],[3,4,2,11],[10,9,13,15]]
14 * Output: 3
15 * Explanation: We can start at the cell (0, 0) and make the following moves:
16 * - (0, 0) -> (0, 1).
17 * - (0, 1) -> (1, 2).
18 * - (1, 2) -> (2, 3).
19 * It can be shown that it is the maximum number of moves that can be made.
20 * <strong class="example">Example 2:
21 * 
22 * <img alt="" src="https://assets.leetcode.com/uploads/2023/04/12/yetgrid4drawio.png" />
23 * Input: grid = [[3,2,4],[2,1,9],[1,1,7]]
24 * Output: 0
25 * Explanation: Starting from any cell in the first column we cannot perform any moves.
26 * 
27 *  
28 * Constraints:
29 * 
30 * 	m == grid.length
31 * 	n == grid[i].length
32 * 	2 <= m, n <= 1000
33 * 	4 <= m * n <= 10^5
34 * 	1 <= grid[i][j] <= 10^6
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/maximum-number-of-moves-in-a-grid/
40// discuss: https://leetcode.com/problems/maximum-number-of-moves-in-a-grid/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn max_moves(grid: Vec<Vec<i32>>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2684() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.