what should be the approach to this question as the input format is little bit complicated for me
Find sum at k level problem
hi @AbhishekAhlawat1102
Here, the question says to find out if the sum of all the nodes present at a given level K.
We can reduce the problem into smaller subproblem by traversing the left subtree and right subtree and reducing k whenever we traverse a new level i.e reduce k by -1 at each level. Then we for every left and right subtree call we will check if we are at the correct level or not.
If k becomes zero at any point then we are at our desired level and we will return the data of the node from this level.
If the node is not present we will return 0 as the base case for the problem.
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.