Your question is Morris Traversal Implementation. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Josh Technology Group's engineering tools may need to inspect hierarchical data without allocating traversal stacks for large trees. Given the root of a binary tree, return its inorder traversal using Morris traversal, which temporarily creates and removes predecessor links.
Implement morris_inorder(root). The input is a TreeNode object with integer field val and optional left and right child references. Return a list of values visited in inorder: left subtree, current node, right subtree. The traversal must restore every temporary pointer before returning.
For examples and test cases, trees are represented as level-order arrays, where null means no node. The evaluator constructs the corresponding TreeNode graph before calling the function.
def morris_inorder(root):