2713. Maximum Strictly Increasing Cells in a Matrix Hard

@problem@discussion
#Array#Hash Table#Binary Search#Dynamic Programming#Memoization#Sorting#Matrix#Ordered Set



1/**
2 * [2713] Maximum Strictly Increasing Cells in a Matrix
3 *
4 * Given a 1-indexed m x n integer matrix mat, you can select any cell in the matrix as your starting cell.
5 * From the starting cell, you can move to any other cell in the same row or column, but only if the value of the destination cell is strictly greater than the value of the current cell. You can repeat this process as many times as possible, moving from cell to cell until you can no longer make any moves.
6 * Your task is to find the maximum number of cells that you can visit in the matrix by starting from some cell.
7 * Return an integer denoting the maximum number of cells that can be visited.
8 *  
9 * <strong class="example">Example 1:
10 * <strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/23/diag1drawio.png" style="width: 200px; height: 176px;" />
11 * 
12 * Input: mat = [[3,1],[3,4]]
13 * Output: 2
14 * Explanation: The image shows how we can visit 2 cells starting from row 1, column 2. It can be shown that we cannot visit more than 2 cells no matter where we start from, so the answer is 2. 
15 * 
16 * <strong class="example">Example 2:
17 * <strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/23/diag3drawio.png" style="width: 200px; height: 176px;" />
18 * 
19 * Input: mat = [[1,1],[1,1]]
20 * Output: 1
21 * Explanation: Since the cells must be strictly increasing, we can only visit one cell in this example. 
22 * 
23 * <strong class="example">Example 3:
24 * <strong class="example"><img alt="" src="https://assets.leetcode.com/uploads/2023/04/23/diag4drawio.png" style="width: 350px; height: 250px;" />
25 * 
26 * Input: mat = [[3,1,6],[-9,5,7]]
27 * Output: 4
28 * Explanation: The image above shows how we can visit 4 cells starting from row 2, column 1. It can be shown that we cannot visit more than 4 cells no matter where we start from, so the answer is 4. 
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	m == mat.length 
34 * 	n == mat[i].length 
35 * 	1 <= m, n <= 10^5
36 * 	1 <= m * n <= 10^5
37 * 	-10^5 <= mat[i][j] <= 10^5
38 * 
39 */
40pub struct Solution {}
41
42// problem: https://leetcode.com/problems/maximum-strictly-increasing-cells-in-a-matrix/
43// discuss: https://leetcode.com/problems/maximum-strictly-increasing-cells-in-a-matrix/discuss/?currentPage=1&orderBy=most_votes&query=
44
45// submission codes start here
46
47impl Solution {
48    pub fn max_increasing_cells(mat: Vec<Vec<i32>>) -> i32 {
49        0
50    }
51}
52
53// submission codes end
54
55#[cfg(test)]
56mod tests {
57    use super::*;
58
59    #[test]
60    fn test_2713() {
61    }
62}
63


Back
© 2025 bowen.ge All Rights Reserved.