PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCareers
|Home/Coding & Algorithms/Snowflake

Compute shortest path between tree nodes

Last updated: Mar 29, 2026

Quick Overview

This question evaluates a candidate's ability to work with binary tree algorithms, including tree traversal, lowest common ancestor identification, path reconstruction, and asymptotic complexity analysis.

  • Medium
  • Snowflake
  • Coding & Algorithms
  • Software Engineer

Compute shortest path between tree nodes

Company: Snowflake

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Onsite

You are given the root of a binary tree with unique integer values and two target values u and v. Return the sequence of node values along the shortest path between u and v. If either node does not exist, return an empty list. Solve in O(n) time and O(h) extra space by finding the lowest common ancestor and reconstructing the path from u and v to the LCA. Provide either iterative or recursive implementations and analyze complexity.

Quick Answer: This question evaluates a candidate's ability to work with binary tree algorithms, including tree traversal, lowest common ancestor identification, path reconstruction, and asymptotic complexity analysis.

Related Interview Questions

  • Implement Document Predicate APIs - Snowflake (medium)
  • Find Shortest Wiki Click Path - Snowflake (medium)
  • Schedule prerequisite classes with retakes - Snowflake (easy)
  • Solve three coding rounds - Snowflake (medium)
  • Minimize coins with overpay and change - Snowflake (hard)
Snowflake logo
Snowflake
Sep 6, 2025, 12:00 AM
Software Engineer
Onsite
Coding & Algorithms
2
0

You are given the root of a binary tree with unique integer values and two target values u and v. Return the sequence of node values along the shortest path between u and v. If either node does not exist, return an empty list. Solve in O(n) time and O(h) extra space by finding the lowest common ancestor and reconstructing the path from u and v to the LCA. Provide either iterative or recursive implementations and analyze complexity.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Snowflake•More Software Engineer•Snowflake Software Engineer•Snowflake Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • Careers
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.