Back to Home
Prefix Sums
Prefix Sums let you query subarray sums quickly after one pass.
Key Ideas
- Build
pref[i]= sum of first i elements. - Subarray sum
[l..r]ispref[r+1] - pref[l]. - Hash map of prefix sums helps count subarrays with a target sum.
Practice Problems
Range Sum Query - Immutable
LeetCodeEasy
Practice this problem with interactive visualization.
Start Solving
Subarray Sum Equals K
LeetCodeMedium
Practice this problem with interactive visualization.
Start Solving
Find Pivot Index
LeetCodeEasy
Practice this problem with interactive visualization.
Start Solving