How can i do it iteratively?

how can i do it iteratively?

@Vipin_coder,

use level order traversal. During traversal, if we find a node whose left and right children are NULL, we add that to sum.

okay, which approach is better and why?

@Vipin_coder,
Both methods will have a time complexity of O(n).

Also, try to find the time complexity of a code and compare different approaches on your own.

means both are best?? there is no diff. b/w them?

@Vipin_coder,
you can calculate the space complexity of both the approaches as well to compare.

Of course there is a difference between the implementation of 2 methods. One is a recursive traversal and one is using a queue and an iterative solution.

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.