Max Depth of A Tree - Depth First Search / DFS on Tree

The code is counting nodes that follow a certain path. There will always be for n nodes n-1 edges which is what depth counts for. So subtracting one from the final result gets the correct depth.

1 Like