Skip to content
6
0
:
0
0

Team Hierarchy Traversal

Medium

Trees

In "Team Hierarchy Traversal", 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 = [19,20,21,null,22,23,null]
Output:[[19],[20,21],[22,23]]

For input root = [19,20,21,null,22,23,null], nodes are grouped by depth from top to bottom, yielding [[19],[20,21],[22,23]]. Therefore, return [[19],[20,21],[22,23]].

Example 2

Input:root = [29,30,31,32,null,null,33]
Output:[[29],[30,31],[32,33]]

For input root = [29,30,31,32,null,null,33], nodes are grouped by depth from top to bottom, yielding [[29],[30,31],[32,33]]. Therefore, return [[29],[30,31],[32,33]].

Constraints

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

Test Cases (2)

Test Case 1
Input:
[19,20,21,null,22,23,null]
Expected Output:
[[19],[20,21],[22,23]]
Test Case 2
Input:
[29,30,31,32,null,null,33]
Expected Output:
[[29],[30,31],[32,33]]