6
0
:0
0
Wavefront Tree Scan
Wavefront Tree Scan
Hard
Trees
In "Wavefront Tree Scan", 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 = [16,17,18,null,19,20,null]Output:
[[16],[17,18],[19,20]]For input root = [16,17,18,null,19,20,null], nodes are grouped by depth from top to bottom, yielding [[16],[17,18],[19,20]]. Therefore, return [[16],[17,18],[19,20]].
Example 2
Input:
root = [26,27,28,29,null,null,30]Output:
[[26],[27,28],[29,30]]For input root = [26,27,28,29,null,null,30], nodes are grouped by depth from top to bottom, yielding [[26],[27,28],[29,30]]. Therefore, return [[26],[27,28],[29,30]].
Constraints
0 <= number of nodes <= 2000-1000 <= Node.val <= 1000
solution.js
Loading...
Test Cases (2)
Test Case 1
Input:
[16,17,18,null,19,20,null]Expected Output:
[[16],[17,18],[19,20]]Test Case 2
Input:
[26,27,28,29,null,null,30]Expected Output:
[[26],[27,28],[29,30]]