Morris inorder traversal
Given a binary tree encoded as a level-order array (None marks a missing child), return its inorder traversal using O(1) extra space (no recursion, no explicit stack) via Morris traversal. You may build the tree nodes from the array, but the traversal itself must use threading: temporarily link each node's inorder predecessor's right pointer to the node, then unlink it on the second visit. Return the list of values in inorder.
Implement
morris_inorder(level: list) → list[int]Examples
in
[[1,null,2,null,3]]out[1,2,3]What a strong answer looks like
State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.
0:00 of about 35 min
solution.py
InputExpectedGot
[[1,null,2,null,3]][1,2,3]not run yetsample