This question evaluates understanding of hierarchical data modeling and tree traversal, specifically breadth-first (level-order) traversal and reconstruction of a tree from manager–employee relationships.
You are given an organization chart as manager relationships.
Each employee is represented by:
employee_id
(string/int)
manager_id
(string/int or
null
), where
null
indicates the CEO/root
Assume the org chart forms a valid tree (exactly one root, no cycles), but employees may appear in any order.
Return the employees top-down, level by level (i.e., breadth-first order).
A list of pairs/records:
(employee_id, manager_id)
One of the following (choose one and state which you implement):
[[CEO], [A,B], [C,D,E]]
;
or
Input:
Output (option 1):
[["CEO"], ["A","B"], ["C"]]
O(n)
time and
O(n)
memory.