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