Given two integer arrays preorder and inorder representing the preorder and inorder traversal of a binary tree, construct and return the binary tree, returned here as its level-order array.
Input: preorder = [3,9,20,15,7], inorder = [9,3,15,20,7]
Output: [3,9,20,null,null,15,7]
Topics: trees
Asked by: Amazon, Microsoft, Meta, Bloomberg
Time complexity: O(n). Space complexity: O(n).