Skip to content
6
0
:
0
0

Organization Level Walk: Department Chart Edition

Medium

Trees

In "Organization Level Walk: Department Chart Edition", the binary tree is provided in array form (level-order with null gaps).

Return node values grouped by depth from top to bottom and left to right.

Example 1

Input:root = [22,23,24,null,25,26,null]
Output:[[22],[23,24],[25,26]]

For input root = [22,23,24,null,25,26,null], nodes are grouped by depth from top to bottom, yielding [[22],[23,24],[25,26]]. Therefore, return [[22],[23,24],[25,26]].

Example 2

Input:root = [32,33,34,35,null,null,36]
Output:[[32],[33,34],[35,36]]

For input root = [32,33,34,35,null,null,36], nodes are grouped by depth from top to bottom, yielding [[32],[33,34],[35,36]]. Therefore, return [[32],[33,34],[35,36]].

Constraints

  • 0 <= number of nodes <= 2000
  • -1000 <= Node.val <= 1000
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[22,23,24,null,25,26,null]
Expected Output:
[[22],[23,24],[25,26]]
Test Case 2
Input:
[32,33,34,35,null,null,36]
Expected Output:
[[32],[33,34],[35,36]]