##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
You know knapsack patterns. Now you need a tool that speeds up range computations. Prefix sums turn O(n) range queries into O(1).
Prefix sum DP - teaches how to precompute and reuse subproblem results
Classic 2D prefix sum problem with constant-time rectangle queries.
The definition
Standard prefix sum + hashmap pattern used everywhere.
Handles negative numbers with prefix sum + hashmap technique.
Teaches prefix sum optimization to reduce O(NK²) to O(NK).
Demonstrates when greedy+recursion outperforms pure recursion
Combines 2D prefix sums with hashmap for matrix subarray counting.
Covered with full walkthrough in this section.
Covered with full walkthrough in this section.
Covered with full walkthrough in this section.
Covered with full walkthrough in this section.
Arrange tiles to maximize prime prefix sums. Teaches creative use of prefix sums with number theory.
Reverse engineer a sorted sequence from partial prefix sums. Tests deep understanding of prefix sum properties.
Minimize operations to make a prefix sum the global minimum. Combines greedy with prefix sum analysis.
Count maximal prefix sums across all permutations. Beautiful combinatorics with prefix sums.
Find subarray with sum divisible by k. Classic prefix sum + modular arithmetic + hashmap pattern.
Count subarrays divisible by k. Prefix sum with modular counting - interview favorite.
Longest subarray with equal 0s and 1s. Transform to prefix sum problem with hashmap.
Count subarrays where sum equals length. Prefix sum + hashmap counting pattern.
Count valid triangles with prefix sums. Transforms geometry to array problem.
Count alternating substrings with wildcards. Prefix counting with state tracking.
Maximize wins in RPS with prefix sums. Sliding window + prefix optimization.
Connect forests without creating cycles. DSU with prefix optimization.
Count inversions with merge sort. Classic divide and conquer application.
Simple usage of prefix sum
2D DP with prefix sums combining multiple DP techniques