PracHub
QuestionsPremiumLearningGuidesCheatsheetNEWCoaches
|Home/Coding & Algorithms/Microsoft

Traverse org chart level by level

Last updated: Mar 29, 2026

Quick Overview

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.

  • easy
  • Microsoft
  • Coding & Algorithms
  • Data Scientist

Traverse org chart level by level

Company: Microsoft

Role: Data Scientist

Category: Coding & Algorithms

Difficulty: easy

Interview Round: Technical Screen

## Problem 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. ## Task Return the employees **top-down, level by level** (i.e., breadth-first order). ### Input A list of pairs/records: - `(employee_id, manager_id)` ### Output One of the following (choose one and state which you implement): 1. A list of lists, where each inner list contains employee_ids at the same depth, ordered left-to-right by insertion order (or sorted if you prefer), e.g. `[[CEO], [A,B], [C,D,E]]`; **or** 2. A single list of employee_ids in BFS order. ## Example Input: - ("CEO", null) - ("A", "CEO") - ("B", "CEO") - ("C", "A") Output (option 1): - `[["CEO"], ["A","B"], ["C"]]` ## Constraints / Edge cases - Employees may be given before their manager appears in the input. - Large orgs: aim for `O(n)` time and `O(n)` memory.

Quick Answer: 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.

Related Interview Questions

  • Sort Three Categories In Place - Microsoft (medium)
  • Implement K-Means and Detect Divisible Subarrays - Microsoft (medium)
  • Implement SFT Sample Packing - Microsoft (medium)
  • Implement SQL Table and DNA Ordering - Microsoft (medium)
  • Solve power jumps and graph tour - Microsoft (hard)
Microsoft logo
Microsoft
Feb 9, 2026, 11:59 AM
Data Scientist
Technical Screen
Coding & Algorithms
4
0
Loading...

Problem

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.

Task

Return the employees top-down, level by level (i.e., breadth-first order).

Input

A list of pairs/records:

  • (employee_id, manager_id)

Output

One of the following (choose one and state which you implement):

  1. A list of lists, where each inner list contains employee_ids at the same depth, ordered left-to-right by insertion order (or sorted if you prefer), e.g. [[CEO], [A,B], [C,D,E]] ; or
  2. A single list of employee_ids in BFS order.

Example

Input:

  • ("CEO", null)
  • ("A", "CEO")
  • ("B", "CEO")
  • ("C", "A")

Output (option 1):

  • [["CEO"], ["A","B"], ["C"]]

Constraints / Edge cases

  • Employees may be given before their manager appears in the input.
  • Large orgs: aim for O(n) time and O(n) memory.

Comments (0)

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Microsoft•More Data Scientist•Microsoft Data Scientist•Microsoft Coding & Algorithms•Data Scientist Coding & Algorithms
PracHub

Master your tech interviews with 7,500+ 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.