Skip to content
6
0
:
0
0

Menu Tree Level Listing

Hard

Trees

In "Menu Tree Level Listing", 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 = [6,7,8,null,9,10,null]
Output:[[6],[7,8],[9,10]]

For input root = [6,7,8,null,9,10,null], nodes are grouped by depth from top to bottom, yielding [[6],[7,8],[9,10]]. Therefore, return [[6],[7,8],[9,10]].

Example 2

Input:root = [16,17,18,19,null,null,20]
Output:[[16],[17,18],[19,20]]

For input root = [16,17,18,19,null,null,20], nodes are grouped by depth from top to bottom, yielding [[16],[17,18],[19,20]]. Therefore, return [[16],[17,18],[19,20]].

Constraints

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

Test Cases (2)

Test Case 1
Input:
[6,7,8,null,9,10,null]
Expected Output:
[[6],[7,8],[9,10]]
Test Case 2
Input:
[16,17,18,19,null,null,20]
Expected Output:
[[16],[17,18],[19,20]]