Prefix Sum Problems for Coding Interviews
19 Prefix Sum problems from real coding interviews, each with test cases you can run online. By difficulty they split into 8 basic, 7 intermediate and 4 advanced. The companies that ask them most often are Google, Amazon, Microsoft, Bloomberg.
Solve a few problems of each level, name the pattern after each one and revisit the ones that needed a hint a week later. Practise stating the time and space complexity and the edge cases before you code.
Coding problems
- Minimum Size Subarray Sum (Intermediate)
- Subarray Sum Equals K (Intermediate)
- Find Pivot Index (Basic)
- Running Sum of Array (Basic)
- Prefix Sum Queries (Intermediate)
- Subarray Sum Equals K (Intermediate)
- BST Range Sum (Basic)
- Range Sum With Updates (Intermediate)
- Count Range Sums (Basic)
- Prefix Sum Map (Advanced)
- Range Sum Query 2D (Intermediate)
- Maximum Ascending Subarray Sum (Basic)
- Prefix Sums of a Linked List (Basic)
- Kth Smallest Subarray Sum (Advanced)
- Maximum Subarray Sum With One Deletion (Intermediate)
- Best Subarray Sum With Length Between Bounds (Advanced)
- Range Add Range Sum Queries (Advanced)
- Lowest Prefix of Steps (Basic)
- Adjacent Difference Array (Basic)
Related
Frequently asked questions
How do I get good at prefix sum problems?
Practise by level, name the pattern after you solve each problem and review the ones you needed hints for. The list is ordered so you can start with the basic ones.
Can I run prefix sum problems online here?
Yes. Each problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and more.