#2713
Maximum Strictly Increasing Cells in a Matrix
international master · 1940 · lc hard +32 · verified · 31.4% accepted · 628 likes · top 9%
Description
Given a 1-indexed m x n integer matrix mat, choose any starting cell. From each cell you may jump to any other cell in the same row or column whose value is strictly greater. Return the maximum number of cells that can be visited along any such path.
Example 1:
Input: mat = [[3,1],[3,4]]
Output: 2
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.
Example 2:
Input: mat = [[1,1],[1,1]]
Output: 1
Explanation: Since the cells must be strictly increasing, we can only visit one cell in this example.
Example 3:
Input: mat = [[3,1,6],[-9,5,7]]
Output: 4
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.
Code
1
2
3