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