6
0
:0
0
Layered Branch Output
Layered Branch Output
Hard
Trees
In "Layered Branch Output", 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 = [18,19,20,null,21,22,null]Output:
[[18],[19,20],[21,22]]For input root = [18,19,20,null,21,22,null], nodes are grouped by depth from top to bottom, yielding [[18],[19,20],[21,22]]. Therefore, return [[18],[19,20],[21,22]].
Example 2
Input:
root = [28,29,30,31,null,null,32]Output:
[[28],[29,30],[31,32]]For input root = [28,29,30,31,null,null,32], nodes are grouped by depth from top to bottom, yielding [[28],[29,30],[31,32]]. Therefore, return [[28],[29,30],[31,32]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[18,19,20,null,21,22,null]Expected Output:
[[18],[19,20],[21,22]]Test Case 2
Input:
[28,29,30,31,null,null,32]Expected Output:
[[28],[29,30],[31,32]]