sol: https://ide.codingblocks.com/s/419460
prob: https://hack.codingblocks.com/app/practice/2/276/problem
how do I take the input ?
sol: https://ide.codingblocks.com/s/419460
prob: https://hack.codingblocks.com/app/practice/2/276/problem
how do I take the input ?
You need to take input using preorder format. also use long long int looking at the constraints
when do I put null values, in other questions they have -1, or false to tell that the value is null
int sum(node* root){
if(root==NULL){
return 0;
}
return root->data + sum(root->left) + sum(root->right);
}
node* root=new node(a[mid]);
root->left=build(a,s,mid-1);
root->right=build(a,mid+1,e);
return root;
}
you could intake the array and build like this.or if you notice the question just asks you the sum of all the nodes .just find the sum of all the values in the array .you ll get the answer without building the tree