question:https://codezen.codingninjas.com/practice/499/795/sum-tree
error
https://ideone.com/5sRCgd
Sum tree binary tree
@ayu2321 you are changing every node with its sum of chiledren but if you observe carefully its childrens value will also get changed by there sum of childrens .
So i guess question is replace every node with sum of its left and right subtree nodes.try custom inputs to check if it is just sum of children or sum of its subtrees cause sum tree is the tree with nodes replaced by sum of its left and right subtree.
according to the custom input we need to replace each node with its children rather than left and right subtree
Yeah cause custom input only has 2 layers.
Please try a sample check with tree having more than 2 layers and see if nodes has sum of only children or of subtree
okay fine will do it like this.
in your code you are calling a non void function like void, and in every function you are re declaring the vector so sum won’t be store in same function. it is not said in the problem that tree will be complete tree.
so i have updated your code keeping these things try this https://ide.codingblocks.com/s/298407
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.