0PricingLogin
Competitive Programming Academy · Lesson

Build a Prefix Sum Array

Precompute running totals once.

The Repeated-Sum Problem

Imagine answering hundreds of range-sum questions on one array. Summing each range from scratch is slow. A prefix sum fixes that. 🚀

What a Prefix Sum Is

A prefix sum array stores, at each index, the total of all elements up to that point. One precompute pass turns slow sums into instant answers.

All lessons in this course

  1. Build a Prefix Sum Array
  2. Sum Any Range with Subtraction
  3. Count Subarrays with a Target Sum
  4. Difference Arrays for Range Updates
← Back to Competitive Programming Academy