Floor by Floor
mediumA building inspector works a tree-shaped complex one floor at a time: everything on the current level gets logged before anyone climbs to the next. Her report groups rooms by floor, left to right.
Given the root of a binary tree, return its values grouped by depth: a list of levels, each level a left-to-right list of values.
Tests pass a level-order array; implement the core in _levels on real nodes.
Example 1
in values = [3, 9, 20, null, null, 15, 7]
out [[3], [9, 20], [15, 7]]
Example 2
in values = [1]
out [[1]]
Example 3
in values = []
out []
Constraints
- · 0 <= number of nodes <= 2000
- · -1000 <= node value <= 1000
solution.py● loading python…
test results
Hit ▶ Run to test your code against the visible cases.