Cut trees in order
Your task
You walk a forest grid: 0 is an impassable obstacle, 1 is walkable ground, and any value > 1 is a tree of that height. You start at (0,0) and must cut all trees in strictly increasing order of height (no two trees share a height). Cutting a tree turns it into ground (1). Moving costs 1 per 4-directional step onto a walkable cell. Return the minimum total steps to cut every tree in order; if any tree is unreachable, return -1. The cell (0,0) is walkable (value >= 1) when you start.
Examples
cut_off_trees(forest: list[list[int]]) -> intExample 1
Input
cut_off_trees([[1, 2, 3], [0, 0, 4], [7, 6, 5]])Output
6