Print Org Chart by Level
Company: Microsoft
Role: Data Scientist
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Technical Screen
Quick Answer: This question evaluates the ability to model hierarchical data, work with tree/graph data structures, select traversal strategies, and analyze time and space complexity when converting flat employee records into a hierarchical org chart.
Constraints
- records are (employee_id, manager_id, employee_name).
- Child order follows the input order.
Examples
Input: ([(1,None,"CEO"),(2,1,"Eng"),(3,1,"Sales"),(4,2,"Dev")],)
Expected Output: [['CEO'], ['Eng', 'Sales'], ['Dev']]
Explanation: Level-order traversal from the CEO.
Input: ([],)
Expected Output: []
Explanation: No records produce no levels.
Hints
- Clarify edge cases before coding.
- Keep the return value deterministic.