Find sum at level k

if the children are 1 of a node then where to put that node in left or in right??

@shampblocks hey ,input agr levelwise lerhe ho to ,suppose apko right me chyy left me child nhi chyy to -1 input hoga left ka and right ka dia hoga woh lena hai.

1 2
2 2
3 0
4 0
5 2
6 0
7 0
2
bhaiya input format yeh hai can you explain by adding one node in input which has child 1??

but in question we have to take input in a specific manner?? that -1 thing will not be usefull there??

@shampblocks bhai consider that single node in left:
node* buildTreeGeneric(node*root){
int d,n ;
cin >> d >> n;
root = new node(d,n);
if(n==0){
return root ;
}
else if(n==1){
root->left = buildTreeGeneric(root->left);
return root ;
}
else {
root->left = buildTreeGeneric(root->left);
root->right = buildTreeGeneric(root->right) ;
return root ;
}
}

It is like generic tree.

what is generic tree??

@shampblocks generic tree me do se jada children bhi ho skte hai ,but children is attached from leftmost child,mtlb agr ek hi child hai to pehle left lgega right khali rhega.

but in question this is given there is no more then two children…

@shampblocks hn bhai generic tree with not more than 2 children isme bs ye hint hai ki apko ek child dia ho to use left me lgana hai hmesha right me nhi ayega.

1 Like

ohk bhaiya thanks you clear doubts really well…

@shampblocks welcome

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.