Algorithm · ByteDance · Medium
You receive two integer arrays, preorder and postorder. They are, respectively, the preorder traversal and the postorder traversal of one and the same binary tree. Rebuild a binary tree that produces both traversals and return its root. All node values are distinct, and the input is guaranteed to be valid. When some node has just a single child, the two traversals cannot tell whether that child sits on the left or the right, so more than one tree may fit. To make the answer…