Find the Lowest Common Manager in an Org Chart
Last updated: November 29, 2026
Quick Overview
Given each employee's direct manager, return the lowest person in the reporting chain who is one of two given employees or manages both of them.
Microsoft
November 29, 20260
0
0 solved
Given each employee's direct manager, return the lowest person in the reporting chain who is one of two given employees or manages both of them.
This is a lowest common ancestor problem dressed in the shape of Microsoft Entra ID and the Teams org chart, where each user record stores a manager pointer rather than a list of reports. Interviewers check that you pick the representation that matches the data you are actually given and that you handle one employee being the other's manager.
What the Interviewer Expects
- Notices the input is a parent-pointer map, so walking up is natural
- Handles the case where one employee manages the other
- Handles missing employees and possible disconnected subtrees
- Gives O(h) time and discusses the O(1)-space depth-equalizing variant
- Mentions the top-down recursive version when the input is a tree of reports
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Can you do it in O(1) extra space?
- You will answer millions of such queries on a fixed org: how would you preprocess?
- The data has a bug that creates a reporting cycle: how do you detect it?
- Generalize to the lowest common manager of k employees.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input is a map employee -> manager, with the CEO mapping to None. Given two employees, return the lowest node that is an ancestor-or-self of both. If either is unknown, return None. If one reports u...
High-Level Design
Because every record points up, the cheapest approach is to walk from a to the root collecting the chain in a set, then walk from b upward and stop at the first node in that set. That first hit is...