#3593
Minimum Increments to Equalize Leaf Paths
expert · 1000 · lc medium +32 · 41.2% accepted · 143 likes · top 21%
Description
An undirected tree with n nodes (0-indexed, rooted at 0) has edges [ui, vi]. Each node i has a traversal cost cost[i].
A path's score equals the sum of costs of all nodes along it.
By only increasing (never decreasing) node costs, make all root-to-leaf path scores equal.
Return the minimum number of nodes whose cost must be increased.
Code
1
2
3