All test cases are not passing
Hello @deepaksehrawat150_50930f2fcb83f47e,
Your buildTree function is wrong,
I have implemented one for you,
node* buildTree() {
int first,left,right;
cin>>first;
node* root = new node(first);
queue<node*>q;
q.push(root);
while (!q.empty()) {
node* temp = q.front(); q.pop();
cin>>left>>right;
if (left != -1) {
temp->left = new node(left);
q.push(temp->left);
}
if (right != -1) {
temp->right = new node(right);
q.push(temp->right);
}
}
return root;
}
please clarify why my code is wrong , it is working fine for some test cases and not for others
@deepaksehrawat150_50930f2fcb83f47e,
Test case:
1 2 3 -1 -1 4 -1 -1 5 -1 -1
Tree formed:
1 / \ 2 3 / 4 \ 5
Your Answer:
1 3 5
But Actual Answer:
1 3 4 5
1 Like
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.