Skip to main content
All Questions

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.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.