Practice Cut Off Trees for Golf Event
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Cut Off Trees for Golf Event
Problem Statement
In forest, 0 is blocked ground, 1 is open ground, and a value greater than 1 is the height of a tree on walkable ground. Start at (0, 0) and move horizontally or vertically one cell per step. Cut all trees in increasing height order; cutting changes its cell to 1 and requires no movement step. Trees can be walked through before being cut. Return the minimum walking steps, or -1 if some tree cannot be reached. Tree heights are distinct and at least one tree exists.
Source: Cut Off Trees for Golf Event on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
forest = [[1,2,3],[0,0,4],[7,6,5]]
6
# Example 2
forest = [[1,2,3],[0,0,0],[7,6,5]]
-1
# Example 3
forest = [[2,3,4],[0,0,5],[8,7,6]]
6
Constraints
Related LeetCode Problems
Practice more problems similar to Cut Off Trees for Golf Event.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.