PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep

Quick Overview

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.

  • medium
  • Microsoft
  • Coding & Algorithms
  • Data Scientist

Print Org Chart by Level

Company: Microsoft

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given an organizational chart as a list of employee records: `(employee_id, manager_id, employee_name)`, where `manager_id` is `null` for the CEO. Assume the organization forms a valid tree with exactly one root and no cycles. Build the org chart as a tree, then output the employees level by level from top to bottom, showing all employees in the same layer before moving to the next layer. Explain the data structures you would use, describe the traversal strategy, and analyze the time and space complexity.

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.

Build the org tree from employee records and return employee names level by level.

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

  1. Clarify edge cases before coding.
  2. Keep the return value deterministic.
Last updated: Jun 27, 2026

Loading coding console...

PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.

Related Coding Questions

  • Return Top K Open Businesses - Microsoft (hard)
  • Implement Memory Allocation and In-Memory Records - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Sort Three Categories In Place - Microsoft (medium)
  • Retain Top K Elements - Microsoft (medium)