Find a lesson, question or project

Start typing to search published content and planned structures.

↑ ↓ moveEnter openEsc close
01 / WHAT IT SOLVES

Contiguous range-sum questions and repeated queries over a stable sequence.

02 / HOW TO RECOGNIZE IT
  • contiguous subarray
  • range sum
  • sum ending at this index
03 / PROTECT THIS INVARIANT

prefix is the exact sum from index 0 through the current index.

04 / EXPECTED COST

O(n) preprocessing or scan. Typical auxiliary space: O(1) to O(n), depending on stored history.

JAVA STARTING POINT

A template to adapt, not memorize.

Java
long prefix = 0;
for (int value : values) {
    prefix += value;
    // Compare or store this prefix state.
}

Common mistakes

  • Missing the empty prefix at index -1
  • Using int when sums may overflow
  • Applying a positive-only window to negative values

PUBLISHED / 03

Learn in this order.

Available articles always appear before the publishing plan.

PLANNED PRACTICE

What comes after the published lessons.

  1. Range sum queryPlanned, not yet published