Example 1
- Input
- preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
- Output
- [3,9,20,null,null,15,7]
Root 3 splits inorder into left [9] and right [15,20,7]. Preorder supplies 9 for the left leaf and 20 for the right root. Inside that right span, 15 lies left of 20 and 7 lies right, so both become its children.