Python / BFS - simple working solution
\n    def cutOffTree(self, forest: List[List[int]]) -> int:\n        trees = []\n\n        for i in range(len(forest)):\n            for j in range(len(forest[0
```\n    def cutOffTree(self, forest: List[List[int]]) -> int:\n        trees = []\n\n        for i in range(len(forest)):\n            for j in range(len(forest[0])):\n                if forest[i][j] > 1:\n                    trees.append(forest[i][j])\n\n        trees = sorted(trees)[::-1]\n        start = [0,0]\n        steps = [0]\n\n        while trees:\n            tree_loc = self.find_tree(trees.pop(), start[0], start[1], forest, steps)\n            if not tree_loc:\n                return -1\n            else:\n                start = tree_loc\n\n        return steps[0]\n\n    def find_tree(self, target, r, c, forest, steps):\n        queue = [(r,c,0)]\n        seen = set()\n        while queue:\n            r,c,step = queue.pop(0)\n            if 0 <= r <= len(forest)-1 and 0 <= c <= len(forest[0]) - 1 and (r,c) not in seen and forest[r][c] >= 1:\n                if forest[r][c] == target:\n                    steps[0] += step\n                    return [r,c]\n                seen.add((r,c))\n                queue.append((r+1,c,step+1))\n                queue.append((r-1,c,step+1))\n                queue.append((r,c+1,step+1))\n                queue.append((r,c-1,step+1))\n\n        return False\n```
[]