Can you please help me wih the error

hello @adarshsingh2k
a) the code that u r using is for preorder but in this problem we r given level order traversal
image

b) pass maxlevel by refrence (read difference b/w pass by value and pass by refrence)
image

how to use level order input

@adarshsingh2k
You can maintain a queue of nodes, push the root node inside the queue, then pop the node, but before popping, you need to push its children to the queue…(basically u need to do level order traaversal to construct the tree).
here is the code for better clarity :

node *buildtree() //build tree function to build tree level wise
{
int d;
cin>>d;
queue<node *>q;
node  *root=new node(d);
q.push(root);
int c1,c2;
while(!q.empty())
{
node *  f=q.front();
q.pop();
cin>>c1>>c2;
if(c1!=-1)
{
f->left=new node(c1);
q.push(f->left);
}
if(c2!=-1)
{
f->right=new node(c2);
q.push(f->right);
}
}
return root;
}

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.