Cut trees in order
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.
Implement
cut_off_trees(forest: list[list[int]]) → intExamples
in
[[[1,2,3],[0,0,4],[7,6,5]]]out6What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 40 min
solution.py
InputExpectedGot
[[[1,2,3],[0,0,4],[7,6,5]]]6not run yetsample