
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
The shortest path between any two nodes in a tree must pass through their Lowest Common Ancestor (LCA). The path will travel upwards from node s to the LCA and then downwards from the LCA to node t.
Find the path strings from root → s, and root → t. Can you use these two strings to prepare the final answer?
Remove the longest common prefix of the two path strings to get the path LCA → s, and LCA → t. Each step in the path of LCA → s should be reversed as 'U'.