Dfs_helper in hostel accomodation

I need some more intution on how dfs helper is working.
I didnt even get how dfs is working here.

hello @epic007

dfs helper is simply calculating the number of child nodes (including self) in each subtree and calculaiting contribution of each subtree.

so that is why we have done something like->
count node in parent subtree= sum of count of all nodes in child subtrees + 1

dfs(parent)= 1 + dfs(all children)

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.