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