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

Sign in to watch this lesson
Advanced - Trees Ā· 4:52
Every vertex marks the child with the largest subtree as heavy; a light child has at most half its parent's subtree, so any root path crosses at most log n light edges and touches at most log n heavy chains. A DFS that visits the heavy child first lays every chain, and every subtree, out as a contiguous block of one array, so one segment tree serves them all. A path query repeatedly lifts the chain with the deeper head, one range per chain, for O(log^2 n) per query; edge values are stored at the lower endpoint and the LCA's slot is skipped.