All problems
Deserialize Binary Tree
Problem
Rebuild a binary tree from its preorder serialization and return it in level-order form.
data is a preorder list produced with explicit None markers for missing children. Reconstruct the tree recursively, then emit a LeetCode-style level-order list with None gaps and trailing Nones trimmed. An empty or [None] input returns [].
Return the level-order representation.
Hint
A position pointer that advances on every value or None makes the recursive rebuild simple.
Test cases
case 1
in: [[1,2,null,null,3,null,null]]
expected: [1,2,3]
case 2
in: [[1,null,null]]
expected: [1]
case 3
in: [[]]
expected: []
case 4
in: [[1,null,2,null,null]]
expected: [1,null,2]
Starter codePython
def deserialize_tree(data):
# Your code here
pass4 test cases · run your code against them in the editor