Getting TLE in the question

@Bhavya_Goel, there are two mistakes :-

  1. you should declare array size to be atleast 1000 as n can be at max 1000
  2. you have to print preorder traversal in a new line

corrected code :-

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.