AAlgoLoopSpaced repetition for LeetCode

Prefix Sum

A prefix-sum array precomputes running totals so the sum of any range is answered in O(1) by subtracting two endpoints. Use it when you face many range-sum queries, or to count subarrays whose sum hits a target.

7 LeetCode problems solved with the Prefix Sum pattern. Practice them with spaced repetition so the pattern sticks.

See the full solution

The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.

Start free →