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