What is error in my code
@kailash_01 your buildTree function is wrong.
It is given that a node can have atmax 2 child, value of ācā can be 0, 1, 2.
So you need to consider all these cases.
node* build(){
int v,c;
cin>>v>>c;
node* root=new node(v);
if(c==2){
root->left=build();
root->right=build();
}
else if(c==1){
root->left = build();
}
return root;
}
Also while doing level order traversal in case if(current_level==k) then you are popping the q.front() two times, once inside this if statement and second outside. Just pop it outside the if.
Feel free to ask if you have any other doubt in this question.
Otherwise please mark this doubt as resolved after submitting it.