Determine Reporting Relationships
GoogleSoftware Engineer · Technical ScreenLast updated
This question evaluates understanding of hierarchical relationship modeling, transitive inference across relations, and dynamic data-structure design for tracking manager and peer links.
Build an in-memory organization model that supports three operations on employee IDs:
add_manager(a, b): employeeais the direct manager of employeeb.add_peer(a, b): employeesaandbshare the same direct manager.is_manager(a, b): return whether employeeais a manager of employeeb.
The answer should account for relationships that can be inferred from prior operations. For example, if add_manager(m, x) and add_peer(x, y) were previously recorded, then is_manager(m, y) should return true. You may assume the input is logically consistent and does not create invalid cycles in the org chart.
Explain how you would design the data structures and implement these operations efficiently.
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.