Find the shortest path between two nodes in a Fibonacci tree as a sequence of up, left and right moves.
Unlock detailed company stats for this questionUpgrade
Fibonacci trees are binary trees defined recursively: T_0 is empty, T_1 consists of a single node, and T_n consists of a root node with T_{n-2} as its left child and T_{n-1} as its right child. The nodes in each tree are enumerated using DFS pre-order. Write a function that, given nodes s and e in a Fibonacci tree of order n, returns the shortest path from s to e as a sequence of moves: "U" (up), "L" (left) and "R" (right).
Examples: fibPath(order = 3, start = 1, end = 3) == "URR" fibPath(order = 4, start = 1, end = 4) == "URL" fibPath(order = 5, start = 3, end = 7) == "UURLR"
Expect follow-ups like
- How would the solution change if the tree were enumerated in in-order instead of pre-order?
Community answers
No answers contributed by the community yet.


