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

Sign in to watch this lesson
Advanced - Data Structures and Range Queries · 4:03
When every range query is known in advance and the answer is easy to update one element at a time but impossible to merge (distinct values, the top frequency, equal pairs), Mo's algorithm answers them all by moving a single window. Sorting queries by (l / S, r) with S around √n, and snaking r through alternate strips, keeps the total movement at O((n + Q)√n) add/remove calls. The window must expand before it shrinks, the block size should be a constant, and answers go back to their original indices.