PythiloMedium · 20 min · Task 12 of 20 · progress kept in this browser

Tree level by level

Return the values of a binary tree grouped by depth, top to bottom and left to right within each level.

#      1
#     / \
#    2   3
#         \
#          4
levels(root)  # [[1], [2, 3], [4]]
Your task

Using the Node class in the starter, write levels(root) returning a list of lists of values, one inner list per depth. An empty tree (None) gives [].

Next: Fewest hops