Prefix Sum technique - more useful than you think
Prefix sum is one of those techniques that seems too simple to be useful, but it solves a lot of problems elegantly:
Basic idea: Precompute cumulative sums so any range sum is O(1).
Problems it solves:
- Subarray sum equals K
- Range sum query
- Contiguous array (with hashmap)
- Product of array except self (prefix + suffix products)
- Maximum subarray (Kadane's is basically a prefix sum variant)
2D extension: Prefix sum on matrix for area queries.
Once you recognize the pattern, these problems become trivial. Highly recommend practicing 5-10 prefix sum problems.