⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 18m 44s17 days 22 hours 18 minutes 44 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 18m 44s17 days 22 hours 18 minutes 44 seconds.

Sign in to watch this lesson
Algorithms - Trees and Range Queries · 4:48
Hang a tree from any vertex and the lowest vertex is an end of a longest path; hang it again from there and the string between the two ends pulls tight into a diameter. We prove why the two sweeps work with a swap argument, see them break on negative weights where a tree DP joining the two deepest branches still works, and get every vertex's farthest distance from the diameter's endpoints or by rerooting.