Practice Minimum Number of Visited Cells in a Grid
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Minimum Number of Visited Cells in a Grid
Problem Statement
Start at grid[0][0]. From (i,j), move right within the same row or down within the same column by any positive number of cells up to grid[i][j], staying in bounds. Return the minimum visited-cell count, including the start and destination, to reach the bottom-right cell; return -1 if unreachable.
Source: Minimum Number of Visited Cells in a Grid on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
grid = [[3,4,2,1],[4,2,3,1],[2,1,0,0],[2,4,0,0]]
4
# Example 2
grid = [[3,4,2,1],[4,2,1,1],[2,1,1,0],[3,4,1,0]]
3
# Example 3
grid = [[2,1,0],[1,0,0]]
-1
Constraints
Related LeetCode Problems
Practice more problems similar to Minimum Number of Visited Cells in a Grid.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.