Leetcode Problem 675. Cut Off Trees for Golf Event
675. Cut Off Trees for Golf Event
Leetcode Solutions
BFS Approach for Cutting Trees
Create a list of all trees with their heights and coordinates, and sort it by height.
Initialize the starting point (0, 0) and the total steps taken as 0.
For each tree in the sorted list:
a. Use BFS to find the shortest path from the current position to the tree's position.
b. If the tree is unreachable, return -1.
c. Add the distance to the total steps and update the current position to the tree's position.
Return the total number of steps taken after all trees have been cut.