Step-By-Step Directions From a Binary Tree Node to Another

Medium · Trees · about 25 minutes

Asked at Google, Meta, Snowflake, Databricks, Amazon, Datadog, Confluent, Elastic, Cohere.

The values of a binary tree with n nodes are unique. Return the shortest path from the node with value startValue to the node with value destValue as a string of moves: 'L' (to the left child), 'R' (to the right child) and 'U' (to the parent).

Related guides