Skip to main content

3 docs tagged with "prefix sum"

View all tags

2D Prefix Sum

Extend the Prefix Sum technique to two dimensions — efficiently answer rectangular range sum queries on a 2D grid in O(1) after O(m×n) preprocessing. Includes intuition, dry runs, and multi-language implementations.

Prefix Sum Algorithm

Learn the Prefix Sum technique — a powerful range-query optimization that answers range sum queries in O(1) after O(n) preprocessing. Includes dry runs, complexity analysis, common mistakes, and multi-language implementations.