We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
Build an array where each entry holds the running total, and the sum of any range becomes a single subtraction. Paired with a hash map it answers "how many subarrays sum to k" in one pass - a question that looks like it needs nested loops and does not. It is a small idea with an outsized payoff on medium array problems.
Repeated range-sum queries, or counting subarrays that sum to a target.
8 problems. Each one runs in an in-browser editor against real test cases, with hints and a worked solution.
The patterns cheat sheet covers all of these in one page - what each one looks like in a problem statement, and the template that follows.