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

Sign in to watch this lesson
Advanced - Data Structures and Range Queries · 3:42
A segment-tree node can store anything that merges associatively, as long as the merge has the right identity: (max, count) uses (−∞, 0) and gcd uses 0. Four numbers per node (sum, best prefix, best suffix, best stretch) answer the maximum subarray sum in a range with point updates, where the answer may be the bridge L.suff + R.pref across the middle. Walking down the tree instead of querying it finds the k-th one or the shortest prefix reaching a sum in O(log n) rather than O(log² n), and pruning nodes with max ≤ x finds the first value above x.