Shortest Path Between Nodes
BINARY TREE
Problem
Given the root
of a binary tree and two values start
and dest
, calculate the minimum number of steps required to move from the node with start
to the node with dest
. The path must follow the tree structure.
Examples
shortestPath([1,2,3], 2, 3) // returns 2 // Moving from node 2 to 1 takes one step // and from node 1 to 3 takes another step // totaling two steps.
Loading...
1
2
3