Construct Binary Tree from Preorder and Inorder, four ways

Try:
CALL
1 / 1

Code

The highlighted line runs next. The pill shows the live values in the running call.

Cost

Work done so far, and how the four solutions compare

Arrays and the tree being built

Each node sits above its inorder position

Keyboard: ← → step, Space play or pause. Up to 12 unique values from −1000 to 1000; the two orders must describe the same tree. Output is shown in LeetCode’s level-order format.