Guided lesson

Prefix Sums

Patterns

Prefix Sums

Practice pattern

Mental model

  • Range sum equals prefix[right + 1] - prefix[left].

Operations

build prefix

Cost shape

Build O(n), query O(1)

Watch out

Off-by-one errors.

Related algorithms

Subarray Sum Equals KRange Sum Query
Guided progression
10% lesson
Step 1 / 2Learner goal
Speech settings Speed 1.0 · Volume 90%

Keyboard: Space play/pause · Arrow keys step · Page Up/Down change sections · R restart