An HR dashboard draws the company's org chart one row per management level. The chart comes from the API as nested JSON: each person is { "name": ..., "reports": [...] }, where reports lists their direct reports in display order. reports may be missing or empty.
Write chartRows(chart) that returns an array of rows. Row 0 holds the top person's name, row 1 the names of their direct reports, and so on. Inside a row, names appear left to right: all of the first person's reports, then the next person's, and so on. If chart is null, return [].
Input: chart = {"name":"Ana","reports":[{"name":"Bo","reports":[{"name":"Dee"}]},{"name":"Cy","reports":[{"name":"Eli"},{"name":"Fay"}]}]} Output: [["Ana"],["Bo","Cy"],["Dee","Eli","Fay"]]
Bo's report comes before Cy's reports, because Bo is to the left of Cy.
Input: chart = {"name":"Solo","reports":[]} Output: [["Solo"]]
One person, one row.
0 <= number of people <= 10000Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #323 Org Chart Rows. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.