SUM AT LEVEL K PROBLEM

How to build tree of given example type.
Parent ->children.
1 2
2 2
3 0
4 0
5 2
6 0
7 0

hello @samardeep
recursively do this->
read parent data, build node and then read no of children
if number of child is one then make only one call for its left child.

if number of child is two then make two calls one for its left child and one for its right child.

void buildTree(node* &root){
    int child;
    int d;
    cin>>d;
    root = new node(d);
    cin>>child;
    if(child == 2){
        buildTree(root->left);
        buildTree(root->right);
    }
    else if(d == 1){
        buildTree(root->left);
    }
}

I havent passed two test cases? https://ide.codingblocks.com/s/435450 .whats the error?

check line 37 of ur code, it should be child in place of d

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.