FastPrepPath Between Two Nodes of a Binary Tree
Problems/Path Between Two Nodes of a Binary Tree

Path Between Two Nodes of a Binary Tree

Adobe logoAdobe● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: You write the shortest route between two nodes of a binary tree as a string of up, left and right steps. A post by a CS 1 candidate in Noida, India with three years of experience (October 2023, rejected) describes a single interview of about 80 minutes. It ends with a question about the route between two nodes of a tree. The author asks for the route to be printed and links a task that spells it as steps. The author says they wrote code for it twice, both times with a depth-first search. Once was straight over the tree with only a stack. The other was over a graph made from the tree beforehand. The post gives no limits or examples of its own.

The rules are those of the linked task, so the answer is a string of L, R and U steps. We chose these limits: trees of 2 to 500 nodes, with different values from 1 to 10^4. We wrote new examples.

Our version is about 90% the same as the reported question.

You are given the root of a binary tree whose node values are all different, and two of those values, startValue and destValue. One step moves from a node to its left child (L), to its right child (R) or to its parent (U).

Return the shortest sequence of steps that leads from the node with value startValue to the node with value destValue, written as a string of the letters L, R and U. In a tree there is only one shortest route, so the answer is unique.

Function

stepDirections(root: TreeNode, startValue: int, destValue: int) → String

Examples

Example 1

root = [7,3,11,1,5,9,14,null,null,4,6]startValue = 4destValue = 9return = "UUURL"
root
73154611914

From 4, go up to 5, up to 3 and up to the root 7 (three U steps). Then go right to 11 and left to 9. Answer: "UUURL".

Example 2

root = [2,8,6,null,1,null,null,3]startValue = 2destValue = 3return = "LRL"
root
28136

The start 2 is the root and an ancestor of 3, so no U step is needed: left to 8, right to 1, left to 3. Answer: "LRL".

Example 3

root = [10,20,30,40]startValue = 40destValue = 10return = "UU"
root
10204030

The destination 10 is an ancestor of 40: go up twice, through 20. Answer: "UU".

Constraints

  • The tree has between 2 and 500 nodes.
  • 1 <= node.val <= 10^4, and all node values are different
  • startValue and destValue are values of nodes in the tree, and startValue != destValue

More Adobe Phone Screen questions

  • Evaluate a Parenthesized Integer ExpressionPHONE SCREEN · Seen Oct 2026
  • All Elements of Two BSTs in OrderPHONE SCREEN · Seen Aug 2026
  • Rotate an Array In PlaceOA · PHONE SCREEN · Seen Aug 2026
  • Binary Tree Level-Order Traversal by LevelsPHONE SCREEN · ONSITE INTERVIEW · Seen Aug 2026
  • Count Occurrences in a Sorted ArrayPHONE SCREEN · ONSITE INTERVIEW · Seen Jul 2026
  • Count Pairs with Absolute Difference KPHONE SCREEN · Seen Jul 2026
  • Count Subsets with Sum KPHONE SCREEN · Seen Jul 2026
  • Numbers with Exactly Three DivisorsPHONE SCREEN · Seen Jul 2026
  • Sum of Even Nodes on a Path in a Numbered Binary TreePHONE SCREEN · Seen Jul 2026
  • Largest Value in Every Sliding WindowPHONE SCREEN · Seen Jul 2026

Similar questions at other companies

  • Account Roles With Parent-User InheritanceStripe · PHONE SCREENStripe interview questions
  • Find All Paths for a Name in a File SystemThe Walt Disney Company · PHONE SCREENThe Walt Disney Company interview questions
  • Filesystem Hash TreeCursor · PHONE SCREEN · ONSITE INTERVIEWCursor interview questions
  • Canonical N-Ary Tree CodecApple · PHONE SCREENApple interview questions
  • Find File Paths in a Directory TreeUber · PHONE SCREENUber interview questions
  • Count Distinct Rooted-Tree GraftsThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
  • Serialize and Deserialize a Binary TreeNVIDIA · PHONE SCREENNVIDIA interview questions
  • Print All File and Folder PathsNutanix · PHONE SCREENNutanix interview questions
  • JSON Path Lookup with Implicit Array WildcardsMongoDB · ONSITE INTERVIEWMongoDB interview questions
  • Serialize and Deserialize a Binary TreeGoogle · ONSITE INTERVIEWGoogle interview questions

Interview reports that mention this question

  • Adobe CS1 Interviews: 14 Experiences (Part 4 of 6)

Adobe interview experiences

  • Adobe Web, QA, DevOps, ML Roles: 13 Experiences (Part 3 of 3)
  • Adobe SWE Interviews, Level Unknown: 25 Experiences (Part 2 of 3)
  • Adobe Interviews, Level Unknown: 38 Experiences (Part 1 of 3)
  • Adobe New Grad MTS Interview Questions: 7 Experiences
  • Adobe ML/Research Intern Interviews: 12 Experiences (Part 4 of 4)
All Adobe interview questionsSee Adobe hiring insights
Saved
/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class Solution {
    public String stepDirections(TreeNode root, int startValue, int destValue) {
        // Write your code here.
    }
}
Checking account…