Design read-heavy org chart subordinate counts
MicrosoftSoftware Engineer · OnsiteLast updated
Evaluates understanding of tree/graph data modeling, dynamic indexing, and consistency and concurrency control for maintaining aggregate subordinate counts under updates; Category/Domain: System Design.
You are given manager→direct-report relationships for an organization (an employee has at most one direct manager; the top-level employee has none). Build a data structure/service that supports:
-
Query (read-heavy): given an employee id, return how many total people are in their reporting chain below them (all direct and indirect reports).
-
Update: a relationship can change (e.g., employee X moves from manager A to manager B). After an update, future queries must return correct counts.
Discuss the data model, algorithms, and how you would keep queries fast while handling updates safely (e.g., avoiding cycles).
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.