← Atlassian Interview InsightsSoftware Engineer
The multi-membership twist genuinely tripped me up at first.
Clarify that the problem is a DAG (directed acyclic graph) of organizations with employees as nodes that can belong to multiple orgs. Propose building an ancestor set for each employee by traversing up the org DAG, then intersect the sets to find the deepest common ancestor. Discuss trade-offs between precomputation and on-the-fly computation.
Pro tip: Mention that the org graph is a DAG, not a tree, so you must handle multiple parents and avoid cycles. Also, consider using bitsets for ancestor sets to speed up intersection and depth comparison.
Confirm that employees can belong to multiple organizations, and organizations can have multiple parent organizations, forming a DAG. Ask about the size of the org graph, frequency of queries, and whether updates are expected.
Represent the org hierarchy as a directed acyclic graph (DAG) with adjacency lists for parent pointers. For each employee, store a list of direct memberships. Optionally, precompute ancestor sets for each organization or employee.
For each employee, compute the set of all ancestor organizations by traversing up the DAG (e.g., using DFS/BFS with memoization). If precomputing, store these sets in a hash set or bitset per employee.
Intersect the ancestor sets of the two employees. Among the common ancestors, select the one with maximum depth (longest path from root). If multiple, any deepest works; if none, return null.
Discuss time and space complexity for both precomputation and query. For on-the-fly: O(V+E) per query. For precomputation: O(N*(V+E)) space and time, but O(min(|A|,|B|)) per query. Mention bitset optimizations.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.