Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 48s1 days 16 hours 1 minutes 48 seconds.
Price your future right. 60% off with code BLACKSCHOLES at USD checkout. Offer ends in 1d 16h 01m 48s1 days 16 hours 1 minutes 48 seconds.

Sign in to watch this lesson
Algorithms - Arrays · 4:17
Running totals drawn as a staircase: with P[0] = 0 and P[i] = P[i-1] + a[i-1], the sum of any half-open range [l, r) is the difference of two heights, P[r] - P[l], in constant time after one linear pass. We race 100,000 range queries on a Mac (a naive loop doing 3.3 billion additions versus prefix sums), answer queries given as timestamps with lower_bound and upper_bound, extend the idea to XOR and counts, see why minimum breaks it, and catch the int overflow that a prefix array invites.