Why can't I build the right subtree first and then the left subtree?

In the question : https://practice.geeksforgeeks.org/problems/construct-tree-1/1 which has been discuseed in the Binary Tree section by Prateek bhaiya, he first builds calls the function recursively to build the left subtree, then the right one.

When I tried to build it the other way around, i.e right subtree first and then the left subtree, it gave a segmentation fault as the preOrderIterator kept on increasing, and hence accessing the array went out of bounds.

I cannot seem to understand why we can’t do it the other way around.

For more information regarding the same, please refer to line 69 in the code below

@devpratik
coz humme preorder and inorder de rakha hai
preorder is root left right
preorder mein root print karte hai phir pehle left pe call thats why
agar pehle right pe kardiya toh galat

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.