Output is coming as 4768 but it should be 6478 ! i think the problem is with my build function. if we use the build_2 function, then root will become 4. but in explanation section the root is 5. so how will we construct a build function

yes your build function is incorrect

see the modified code for correct one

Modified Code

i got the logic. but only sample test is passed remaining are still wrong

cout<<endl;
add this line after printing the pre ordertraversal

output of every testcase should be in new line

if you have more doubts regarding this feel free to ask
i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved :grinning:

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.