6
0
:0
0
System Tree Breadth Pass
System Tree Breadth Pass
Hard
Trees
In "System Tree Breadth Pass", 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 = [21,22,23,null,24,25,null]Output:
[[21],[22,23],[24,25]]For input root = [21,22,23,null,24,25,null], nodes are grouped by depth from top to bottom, yielding [[21],[22,23],[24,25]]. Therefore, return [[21],[22,23],[24,25]].
Example 2
Input:
root = [31,32,33,34,null,null,35]Output:
[[31],[32,33],[34,35]]For input root = [31,32,33,34,null,null,35], nodes are grouped by depth from top to bottom, yielding [[31],[32,33],[34,35]]. Therefore, return [[31],[32,33],[34,35]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[21,22,23,null,24,25,null]Expected Output:
[[21],[22,23],[24,25]]Test Case 2
Input:
[31,32,33,34,null,null,35]Expected Output:
[[31],[32,33],[34,35]]