6
0
:0
0
Family Tree Layer Output: Building Map Edition
Family Tree Layer Output: Building Map Edition
Medium
Trees
In "Family Tree Layer Output: Building Map Edition", 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 = [24,25,26,null,27,28,null]Output:
[[24],[25,26],[27,28]]For input root = [24,25,26,null,27,28,null], nodes are grouped by depth from top to bottom, yielding [[24],[25,26],[27,28]]. Therefore, return [[24],[25,26],[27,28]].
Example 2
Input:
root = [34,35,36,37,null,null,38]Output:
[[34],[35,36],[37,38]]For input root = [34,35,36,37,null,null,38], nodes are grouped by depth from top to bottom, yielding [[34],[35,36],[37,38]]. Therefore, return [[34],[35,36],[37,38]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[24,25,26,null,27,28,null]Expected Output:
[[24],[25,26],[27,28]]Test Case 2
Input:
[34,35,36,37,null,null,38]Expected Output:
[[34],[35,36],[37,38]]