Sum of distance in Tree Leetcode

I didn’t understand O(N) Solution .Help!!

hello @Bhawna

read about in and out dp on tree(watch rachit jain dp playlist)
its a standard technique that we use on tree .

if after watching that u still left with any doubt then ping me back.

@ I have solved now Thanks

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.