6
0
:0
0
Binary Layer Collector
Binary Layer Collector
Medium
Trees
In "Binary Layer Collector", 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 = [12,13,14,null,15,16,null]Output:
[[12],[13,14],[15,16]]For input root = [12,13,14,null,15,16,null], nodes are grouped by depth from top to bottom, yielding [[12],[13,14],[15,16]]. Therefore, return [[12],[13,14],[15,16]].
Example 2
Input:
root = [22,23,24,25,null,null,26]Output:
[[22],[23,24],[25,26]]For input root = [22,23,24,25,null,null,26], nodes are grouped by depth from top to bottom, yielding [[22],[23,24],[25,26]]. Therefore, return [[22],[23,24],[25,26]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[12,13,14,null,15,16,null]Expected Output:
[[12],[13,14],[15,16]]Test Case 2
Input:
[22,23,24,25,null,null,26]Expected Output:
[[22],[23,24],[25,26]]