Skip to content
6
0
:
0
0

Server Rack Level Scan

Hard

Trees

In "Server Rack Level Scan", 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 = [3,4,5,null,6,7,null]
Output:[[3],[4,5],[6,7]]

For input root = [3,4,5,null,6,7,null], nodes are grouped by depth from top to bottom, yielding [[3],[4,5],[6,7]]. Therefore, return [[3],[4,5],[6,7]].

Example 2

Input:root = [13,14,15,16,null,null,17]
Output:[[13],[14,15],[16,17]]

For input root = [13,14,15,16,null,null,17], nodes are grouped by depth from top to bottom, yielding [[13],[14,15],[16,17]]. Therefore, return [[13],[14,15],[16,17]].

Constraints

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

Test Cases (2)

Test Case 1
Input:
[3,4,5,null,6,7,null]
Expected Output:
[[3],[4,5],[6,7]]
Test Case 2
Input:
[13,14,15,16,null,null,17]
Expected Output:
[[13],[14,15],[16,17]]