Level Order Traversal
Write the code, see it run, pass the checks.
The problem
- medium
- Code
Write levelOrder(root). A binary tree is made of nodes { value, left, right }, where left and right are child nodes or null; an empty tree is null. Return the values level by level from the top: an array holding one array per level, with that level's values from left to right. Return an empty array for an empty tree, and don't change the tree. For example, the tree written in level order as [3, 9, 20, null, null, 15, 7], with null for a missing child, gives [[3], [9, 20], [15, 7]].
Your code must pass
- Groups the values by level, left to right
- Handles an uneven tree
- Handles an empty tree and a single node
- Doesn't change the tree