PracHub
QuestionsCoachesLearningGuidesInterview Prep

Quick Overview

This question evaluates proficiency with tree data structures and algorithmic problem-solving, specifically reasoning about Lowest Common Ancestor computations on nodes with parent pointers and assessing time and space complexity.

  • Medium
  • Meta
  • Coding & Algorithms
  • Software Engineer

Find Lowest Common Ancestor with Parents

Company: Meta

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: Medium

Interview Round: Technical Screen

##### Question LeetCode 1650. Lowest Common Ancestor of a Binary Tree III Compute the time and space complexity of your solution https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree-iii/description/

Quick Answer: This question evaluates proficiency with tree data structures and algorithmic problem-solving, specifically reasoning about Lowest Common Ancestor computations on nodes with parent pointers and assessing time and space complexity.

You are given a tree of n nodes labeled 0..n-1 represented by an array parents of length n, where parents[i] is the parent of node i, or -1 if i is the root. Given two node indices p and q, return the index of their lowest common ancestor (the deepest node that is an ancestor of both).

Constraints

  • Let n = len(parents).
  • Nodes are labeled from 0 to n-1.
  • Exactly one index r has parents[r] == -1 (the root).
  • parents describes a valid tree (no cycles, every non-root has exactly one parent).
  • 0 <= p, q < n.
  • 1 <= n <= 200000.

Hints

  1. Simulate parent pointers using indices and two pointers: when one pointer reaches the root sentinel (-1), redirect it to the other start node.
  2. Alternatively, collect all ancestors of one node in a set and walk up from the other until you find the first common node.
  3. Handle the trivial case p == q immediately.
Last updated: Mar 29, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

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

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • AI Coding 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.

Related Coding Questions

  • Find Shortest Unique Prefixes - Meta (medium)
  • Compute Exclusive Execution Times - Meta (medium)
  • Solve Tree Columns And Maze Variants - Meta (medium)
  • Solve Tree Diameter and Palindromic Counts - Meta (medium)
  • Simulate Monster Team Battles - Meta (hard)