Prefix Sum
Precompute running totals so the sum of any range can be answered instantly instead of adding it up every time.
Prefix Sum Practice Problems
Easy
2 problemsMedium
6 problems- 111medium
Subarray Sum Equals K
Count how many contiguous subarrays add up to a target value.
- 112medium
Product of Array Except Self
Return an array where each element is the product of every other element, without using division.
- 113medium
Contiguous Array
Find the longest contiguous subarray with an equal number of 0s and 1s.
- 114medium
Range Sum Query 2D - Immutable
Answer repeated queries for the sum of values inside a rectangle of a fixed grid.
- 266medium
Continuous Subarray Sum
Check whether a contiguous subarray of size at least two sums to a multiple of k.
- 267medium
Maximum Size Subarray Sum Equals k
Find the longest contiguous subarray that sums to exactly k.
Hard
1 problemsRelated concepts
| Topic | Description |
|---|---|
| Kadane's Algorithm | Track the best running sum ending at each position to find the maximum sum of a contiguous subarray in one pass. |
| Hash Tables | Key-to-value lookup in average O(1) via hashing into buckets. |
| Sliding Window | Solve fixed-window problems: maximum sum of k elements, moving averages, and O(n) updates as the window slides. |
| Two Pointers | Scan a sorted array or string from both ends at once to find pairs, remove duplicates, or reverse data in O(n). |
| Binary Search | Cut a sorted range in half on every step to find a value or boundary in O(log n) instead of checking one by one. |
| Depth-First Search | Explore as far as possible down one path before backtracking, used to walk trees, graphs, and grids. |