DSA sheet · Prefix Sum

Prefix Sum DSA Notebook

My study notes from the Prefix Sum playlist. Each page is written so that a beginner (or me, after forgetting everything) can read it once and understand the intuition, how the brute force turns into the optimal idea, the Python code line by line, and a full dry run with the prefix array (and hashmap) drawn step by step.

The one idea behind every page Build a running total once: prefix[i] = nums[0] + … + nums[i]. After that, the sum of any piece nums[l..r] is just prefix[r] − prefix[l−1], one subtraction instead of a loop.
Add a hashmap of earlier prefix sums and you can ask "did some earlier point leave exactly the gap I need?" in O(1). That's the trick behind most of these problems.

Every page follows the same order:
① question in simple words → ② constraints → ③ intuition → ④ building the logic from examples → ⑤ approach steps → ⑥ code → ⑦ line by line → ⑧ dry run → ⑨ complexity & remember

1D prefix sums

Prefix sum + hashmap

2D prefix sums

Numbers follow the playlist order (videos 1 and 2 share page 1). "Next →" at the top of each page follows that order. A gentle reading order for beginners: Pivot Index → Product Except Self → Subarray Sum Equals K → Continuous Subarray Sum → Matrix Block Sum.