Class Solution
java.lang.Object
g2701_2800.s2713_maximum_strictly_increasing_cells_in_a_matrix.Solution
2713 - Maximum Strictly Increasing Cells in a Matrix.<p>Hard</p>
<p>Given a <strong>1-indexed</strong> <code>m x n</code> integer matrix <code>mat</code>, you can select any cell in the matrix as your <strong>starting cell</strong>.</p>
<p>From the starting cell, you can move to any other cell <strong>in the</strong> <strong>same row or column</strong> , but only if the value of the destination cell is <strong>strictly greater</strong> 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.</p>
<p>Your task is to find the <strong>maximum number of cells</strong> that you can visit in the matrix by starting from some cell.</p>
<p>Return <em>an integer denoting the maximum number of cells that can be visited.</em></p>
<p><strong>Example 1:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2023/04/23/diag1drawio.png" alt="" /></strong></p>
<p><strong>Input:</strong> mat = [[3,1],[3,4]]</p>
<p><strong>Output:</strong> 2</p>
<p><strong>Explanation:</strong> 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.</p>
<p><strong>Example 2:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2023/04/23/diag3drawio.png" alt="" /></strong></p>
<p><strong>Input:</strong> mat = [[1,1],[1,1]]</p>
<p><strong>Output:</strong> 1</p>
<p><strong>Explanation:</strong> Since the cells must be strictly increasing, we can only visit one cell in this example.</p>
<p><strong>Example 3:</strong></p>
<p><strong><img src="https://assets.leetcode.com/uploads/2023/04/23/diag4drawio.png" alt="" /></strong></p>
<p><strong>Input:</strong> mat = [[3,1,6],[-9,5,7]]</p>
<p><strong>Output:</strong> 4</p>
<p><strong>Explanation:</strong> 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.</p>
<p><strong>Constraints:</strong></p>
<ul>
<li><code>m == mat.length</code></li>
<li><code>n == mat[i].length</code></li>
<li><code>1 <= m, n <= 10<sup>5</sup></code></li>
<li><code>1 <= m * n <= 10<sup>5</sup></code></li>
<li><code>-10<sup>5</sup> <= mat[i][j] <= 10<sup>5</sup></code></li>
</ul>
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
Solution
public Solution()
-
-
Method Details
-
maxIncreasingCells
public int maxIncreasingCells(int[][] mat)
-