6
0
:0
0
Branch Depth Snapshot
Branch Depth Snapshot
Medium
Trees
In "Branch Depth Snapshot", 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 = [9,10,11,null,12,13,null]Output:
[[9],[10,11],[12,13]]For input root = [9,10,11,null,12,13,null], nodes are grouped by depth from top to bottom, yielding [[9],[10,11],[12,13]]. Therefore, return [[9],[10,11],[12,13]].
Example 2
Input:
root = [19,20,21,22,null,null,23]Output:
[[19],[20,21],[22,23]]For input root = [19,20,21,22,null,null,23], nodes are grouped by depth from top to bottom, yielding [[19],[20,21],[22,23]]. Therefore, return [[19],[20,21],[22,23]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[9,10,11,null,12,13,null]Expected Output:
[[9],[10,11],[12,13]]Test Case 2
Input:
[19,20,21,22,null,null,23]Expected Output:
[[19],[20,21],[22,23]]