Challenge
Return a list of tree levels, each containing values from left to right. The first level contains only the root. Empty input returns []. The tree is a flat list: nodes[i]=[value, left_index, right_index]. Child indices are zero-based or null (None in Python). The root is index 0. All nodes are reachable exactly once, no cycles or shared children exist, and indices do NOT imply positions in a complete binary tree.
Input and output contract
0 ≤ n ≤ 2,000; |node value| ≤ 1,000,000. A child can have a smaller index than its parent except that the root is 0. Output is nested lists of VALUES, not node indices. w denotes maximum level width.
All tests follow this contract. You do not need to validate malformed input. Return the requested result from binary_tree_level_order; printed output is not your answer. Standard-library tools are allowed. Implement your solution in Python 3.12.
Target complexity: O(n) time; O(w) auxiliary space plus O(n) output
Return values are checked by type. Use the exact function name. Print output is not your answer. Tests have time and memory limits.
Public examples
Arguments
[[[10, 2, 1], [30, None, None], [20, None, 3], [40, None, None]]]
Expected return
[[10], [20, 30], [40]]
Arguments
[[]]
Expected return
[]
Arguments
[[[7, None, None]]]
Expected return
[[7]]
Hint
At the start of each level, remember the current queue length. Process exactly that many nodes.
The worked solution unlocks after completion, or with Premium access.