Medium · Trees
Step-By-Step Directions From a Binary Tree Node to Another
Given the root of a binary tree whose n nodes have the distinct values 1 to n, and two different values startValue and destValue, return the shortest route from the start node to the destination node. Write the route as a string of 'L' (move to the left child), 'R' (move to the right child) and 'U' (move to the parent).
Examples
Example 1
tree=[5,1,2,3,null,6,4], start=3, dest=6Output: "UURL"
Example 2
tree=[2,1,null], start=2, dest=1Output: "L"
Rebuild it in the studio
Open every published interview problem, solution, scene, and memory room free, with no account.