Skip to content
6
0
:
0
0

Grid Command Tree Levels

Easy

Trees

In "Grid Command Tree Levels", 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 = [20,21,22,null,23,24,null]
Output:[[20],[21,22],[23,24]]

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

Example 2

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

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

Constraints

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

Test Cases (2)

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