Skip to content
6
0
:
0
0

Site Map Level Order

Easy

Trees

In "Site Map Level Order", 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 = [10,11,12,null,13,14,null]
Output:[[10],[11,12],[13,14]]

For input root = [10,11,12,null,13,14,null], nodes are grouped by depth from top to bottom, yielding [[10],[11,12],[13,14]]. Therefore, return [[10],[11,12],[13,14]].

Example 2

Input:root = [20,21,22,23,null,null,24]
Output:[[20],[21,22],[23,24]]

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

Constraints

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

Test Cases (2)

Test Case 1
Input:
[10,11,12,null,13,14,null]
Expected Output:
[[10],[11,12],[13,14]]
Test Case 2
Input:
[20,21,22,23,null,null,24]
Expected Output:
[[20],[21,22],[23,24]]