ā” Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 31s17 days 22 hours 19 minutes 31 seconds.
ā” Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 19m 31s17 days 22 hours 19 minutes 31 seconds.

Sign in to watch this lesson
Advanced - Trees Ā· 5:32
A tree DP computes each vertex's value from its children's values in one sweep from the leaves, like subtree sizes or the sum of distances inside a subtree. Rerooting adds a second sweep from the root that hands every child a summary of the rest of the tree, so an answer for every possible root costs O(n) in total; for the sum of distances the rule is f(c) = f(p) + n - 2*sz[c]. When the combining operation cannot be undone, such as max, each child gets the best of its siblings from prefix and suffix maxima.