Skip to main content
PProfileMatch
← Path

Arrays and Strings · Prefix Sums and Difference Arrays in Python: Range Queries and Updates

0 XP
  1. 1 current stop: learning
  2. 2 upcoming
  3. 3 upcoming
  4. 4 upcoming
  5. 5 upcoming

Finish after stop 5

Stop 1 of 5 · Mile markers along the coast road

Trick to keep in mind+3 XP

prefix[i] is the total of the first i values, so end is exclusive.

Because prefix[i] covers indexes 0 to i - 1, subtracting two prefix values leaves the items from the lower index up to just before the higher one. For values 0 to 1 inclusive, that is prefix[2] - prefix[0]. To include a last index, use last + 1 as the upper position.

Read it once, then a question tests whether the trick stuck.