Organization Chart by Level
Updated
Problem statement
An organization contains employees numbered from 0 through n - 1. The array manager describes a rooted tree: employee 0 is the root and has manager -1; for every other employee i, manager[i] is that employee's direct manager.
Return the complete organization chart one layer at a time from the root downward. Employees within each layer must appear in increasing employee-number order.
Function
organizationLevels(manager: int[]) → int[][]Examples
Example 1
manager = [-1,0,0,1,1,2]return = [[0],[1,2],[3,4,5]]Employee 0 is the root, employees 1 and 2 form the next layer, and their reports form the third.
Example 2
manager = [-1]return = [[0]]A one-person organization has one layer.
Constraints
1 <= manager.length <= 100000manager[0] = -1- For
1 <= i < manager.length,0 <= manager[i] < i
More Microsoft Onsite Interview questions
- Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
- Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
- Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
- Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
- Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
- Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
- Coin ChangeONSITE INTERVIEW · Seen Oct 2026
- Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
- Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Diameter of Binary TreeeBay · ONSITE INTERVIEWeBay interview questions
- Maximum Depth of Binary TreeLinkedIn · PHONE SCREEN · ONSITE INTERVIEWLinkedIn interview questions
- Binary Tree Level-Order Traversal by LevelsAdobe · PHONE SCREEN · ONSITE INTERVIEWAdobe interview questions
- Check Whether All Leaves Are at the Same LevelAmazon · ONSITE INTERVIEW
- Symmetric Binary TreeFigma · ONSITE INTERVIEWFigma interview questions
- Tree Level with the Most NodesBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Mirror Image Binary TreesExpedia · ONSITE INTERVIEWExpedia interview questions
- Mirror a Binary TreeAMD · ONSITE INTERVIEWAMD interview questions
- Symmetric TreeZillow · ONSITE INTERVIEWZillow interview questions
- Find a Node’s Level in an N-ary TreeMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions