Search
⌘K
Get Premium
Leetcode 834. Sum of Distances in Tree
Given a tree with n (≤ 3·10^4) nodes, compute for every node the sum of distances to all other nodes. This requires an O(n) tree-DP / rerooting approach (aggregate subtree sizes and distance sums, then propagate results) rather than repeated BFS from each node.
Question Timeline
See when this question was last asked and where, including any notes left by other candidates.
All Regions
Comments
Hello Interview Premium
Your account is free and you can post anonymously if you choose.