Skip to content

Prefix Sum problems,
and the tell.

The question asks about the sum of many ranges, or how often a running total repeats. 98 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. The question asks about the sum of many ranges, or how often a running total repeats.

The mechanism. Build an array where position i holds the total up to i. Any range sum is then one subtraction, and counting subarrays with a given sum becomes a map of prefix totals seen so far.

What goes wrong. The empty prefix. A map that does not start with the total zero seen once misses every subarray that begins at index zero.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Number of Divisible SubstringsMediumasked at 4 companies
  2. Product of the Last K NumbersMediumasked at 2 companies
  3. Minimum Array Changes to Make Differences EqualMediumasked at 1 companies
  4. Find Polygon With the Largest PerimeterMediumasked at 1 companies
  5. Split Array with Equal SumHardasked at 1 companies
  6. Count Submatrices with Top-Left Element and Sum Less Than kMediumasked at 1 companies
  7. Minimum Moves to Make Array ComplementaryMediumasked at 1 companies
  8. Number of Sub-arrays With Odd SumMediumasked at 1 companies
  9. Maximum White Tiles Covered by a CarpetMediumasked at 1 companies
  10. Special Array IIMediumasked at 1 companies

Read it, watch it, then solve it.

The order that makes a pattern stick.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About prefix sum problems.

Free to start, no card.

Start practising
How do I know a problem is a prefix sum problem?

The question asks about the sum of many ranges, or how often a running total repeats.

How many prefix sum problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 98, split roughly 6 easy, 66 medium and 26 hard in the sample we show, so work up rather than across.

What goes wrong most often in prefix sum problems?

The empty prefix. A map that does not start with the total zero seen once misses every subarray that begins at index zero.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.