We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Concept: find subtree sum and calculate the min of :
abs( (total_sum - subtree_sum_i) - subtree_sum_i)
Warning: Do not use recursive to solve. In Python, DFS on the graph may cause "max recursive depth exceed" error. (In Python the max depth is 1000, typically)
Cut the Tree
You are viewing a single comment's thread. Return to all comments →
Simple C++ Solution:
Concept: find subtree sum and calculate the min of : abs( (total_sum - subtree_sum_i) - subtree_sum_i)
Warning: Do not use recursive to solve. In Python, DFS on the graph may cause "max recursive depth exceed" error. (In Python the max depth is 1000, typically)