Skip to content
6
0
:
0
0

Route Tree Breadth Read: Routing Table Edition

Easy

Trees

In "Route Tree Breadth Read: Routing Table 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 = [25,26,27,null,28,29,null]
Output:[[25],[26,27],[28,29]]

For input root = [25,26,27,null,28,29,null], nodes are grouped by depth from top to bottom, yielding [[25],[26,27],[28,29]]. Therefore, return [[25],[26,27],[28,29]].

Example 2

Input:root = [35,36,37,38,null,null,39]
Output:[[35],[36,37],[38,39]]

For input root = [35,36,37,38,null,null,39], nodes are grouped by depth from top to bottom, yielding [[35],[36,37],[38,39]]. Therefore, return [[35],[36,37],[38,39]].

Constraints

  • 0 <= number of nodes <= 2000
  • -1000 <= Node.val <= 1000
solution.js
Loading...

Test Cases (2)

Test Case 1
Input:
[25,26,27,null,28,29,null]
Expected Output:
[[25],[26,27],[28,29]]
Test Case 2
Input:
[35,36,37,38,null,null,39]
Expected Output:
[[35],[36,37],[38,39]]