i dont understand the input?
1 2
2 2
3 0
4 0
5 2
6 0
7 0
2
Trees -- Find sum at level K
@Shreya-Gupta-2383169445069382
This particular problem asks you to take a generic tree input . A generic tree is a tree where any node can have any number of children (unlike binary trees where a node can have atmost 2 children).
The first integer in each row indicates the data at the node whereas the second integer indicates the no of children that node has .
Refer to this code for the input function - https://ide.codingblocks.com/s/90995
As for the sample testcase given in the problem
1 2
2 2
3 0
4 0
5 2
6 0
7 0
2
Here the tree looks like
1 Level 0
/ \
2 5 Level 1
/ \ / \
3 4 6 7 Level 2
Sum at Level 2 = 3 + 4 + 6 + 7 = 20
Here’s another testcase for you to try
Input :
2 2
1 1
5 0
6 2
3 0
7 0
2
Expected Output : 15
Hit like if you understand.
what is the order? i mean which nodes after which?
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.