root of a binary tree with n nodes, all with distinct values. You also get the values of two different nodes of this tree, start and finish.
Describe the shortest path from node start to node finish as a string of letters:
- 'L' means go to the left child;
- 'R' means go to the right child;
- 'U' means go up to the parent.
Return that string.root=tree_node([4, 2, 6, 1, 3, 5]), start=3, finish=5 → 'UURL'
The path is 3 → 2 → 4 → 6 → 5: two steps up, then right and left.
root=tree_node([1, None, 2]), start=1, finish=2 → 'R'
Node 2 is the right child of the root.
root=tree_node([3, 1, 2]), start=2, finish=3 → 'U'
root=tree_node([4, 2, 6, 1, 3, 5]), start=3, finish=5
'UURL'
Run checks the first 3 tests in your browser. Submit checks all 72 tests on the server, hidden ones included.