← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

IntermediatePrefer not to say
Apr 2026

Summary

Snowflake coding round with a tree traversal problem. Nothing too wild but the path-finding angle made it trickier than a standard LCA question.

Questions Asked (1)

Q1

Given a binary tree and two nodes A and B, return the shortest sequence of moves (up to parent, left to left child, right to right child) that walks from node A to node B.

Algorithms & Data Structures
Author's notes

The key insight is that you go up from A to the lowest common ancestor and then descend to B.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Find the lowest common ancestor (LCA) of A and B, then construct the path from A up to the LCA and from the LCA down to B. The shortest sequence is the concatenation of these two paths, with moves represented as 'up', 'left', or 'right'.

Pro tip: Clarify whether the tree has parent pointers; if not, you'll need to traverse from the root to find the LCA. Also, discuss edge cases like when A or B is the LCA, or when one node is an ancestor of the other.

1. Clarify assumptions

Ask if nodes have parent pointers, if the tree is binary, and if A and B are guaranteed to exist. This determines the approach for finding the LCA.

2. Find the LCA

If parent pointers exist, walk up from A and B to find the LCA. Otherwise, use a recursive or iterative traversal from the root to find the LCA.

3. Build path from A to LCA

Starting from A, repeatedly move to its parent until reaching the LCA, recording each move as 'up'.

4. Build path from LCA to B

Find the path from LCA to B by traversing down from LCA to B, recording 'left' or 'right' moves accordingly.

5. Combine and return

Concatenate the up moves and the down moves to form the shortest sequence of moves from A to B.

Key Points to Mention

  • Lowest Common Ancestor (LCA) is the key to finding the shortest path.
  • The path from A to B goes up from A to LCA, then down from LCA to B.
  • Moves are represented as 'up', 'left', or 'right'.
  • Time complexity: O(h) for finding LCA and building paths, where h is tree height.
  • Space complexity: O(h) for storing paths or recursion stack.
  • Edge cases: A equals B, A is ancestor of B, or B is ancestor of A.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.