Trees -- Find sum at level K

Rectify my code

@Legendankit could you provide the question.
Also it would be better if you open doubt where it happens, then we would be able to help you efficiently.

Take input of a generic tree using buildtree() function and also take input K the level at which we need to find the sum.

Input Format
Take a generic tree input where you are first given the data of the node and then its no of children. The input is of preorder form and it is assured that the no of children will not exceed 2. The input of the tree is followed by a single integer K.

Constraints
1 <= Nodes in tree <=1000
1<K<10

for your reference

@Legendankit issue is in your build tree function , you are not reading the tree properly.

You are not returning the root when num==2.
If this resolves your doubt mark it as resolved

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.