Trees find sum at level K

code link : https://ide.codingblocks.com/s/183071
why I am getting sum 0 please specify the reason and correct my code

@Divya_321
Hello Divya,
the bug is in ur build function.
remove that if statement in line no - 19

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.

@aman212yadav but then it won’t be infinite recursion, which base case should I inlcude in it than

@Divya_321
no it wont because u r already returing root node in case number of child is 0.

now getting no output

@Divya_321
hello divya,
check this code -> https://ide.codingblocks.com/s/198705

1 Like

@aman212yadav in the code you have given,what is the logic that you have used such that just before the input of k the build function returns the root?