Lowest Common Manager of Two Employees With Parent Links

Last updated: November 29, 2026

Quick Overview

Each employee node has a pointer to their manager (the CEO's manager is None). Given two employee nodes, return their lowest common manager, which may be one of the two employees themselves.

LinkedIn
Coding & Algorithms
Software Engineer
LinkedIn
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Each employee node has a pointer to their manager (the CEO's manager is None). Given two employee nodes, return their lowest common manager, which may be one of the two employees themselves.

Org charts appear across LinkedIn's company pages and Talent products. This short screen question checks LCA with parent pointers and whether you find the O(1) space two-pointer trick after the hash set version.

What the Interviewer Expects
  • Offers the hash set of ancestors approach first
  • Improves to two pointers that switch to the other start when reaching the top
  • Explains why both pointers meet after at most depth(a) + depth(b) steps
  • Handles one employee being the other's manager
  • Uses O(1) extra space in the final version
Key Topics to Cover
binary trees
lowest common ancestor
two pointers
parent pointers
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if you only have a child list from the root and no parent pointers?
  • How would you answer many LCA queries quickly?
  • How would you find the distance between two employees in the chart?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Nodes have name and manager. Both nodes are in the same tree. Return the deepest node that is an ancestor of both, where a node counts as its own ancestor....

High-Level Design

Hash set version: walk from a to the root storing nodes, then walk from b until hitting the set. O(h) time and space. Two-pointer version: pointer p starts at a and q at b; each step moves to its mana...


Submit Your Answer
Markdown supported