Prefix Sum

Precompute running totals so the sum of any range is a single subtraction. Pair it with a hash map when you need subarrays with a given sum, as in Subarray Sum Equals K. It turns repeated range sums from linear into constant time.

15 problems · 6 with a video · 3 to practice in an AI round

Prefix Sum problems
#ProblemDifficultyVideoAI round
1Product of Array Except SelfMediumAI round
2Subarray Sum Equals KMediumAI round
3Find Pivot IndexEasyAI round
4Contiguous ArrayMedium
5Running Sum of 1d ArrayVery easy—
6Subarray Sums Divisible by KMedium—
7Continuous Subarray SumMedium—
8Find the Highest AltitudeVery easy—
9Make Sum Divisible by PMedium—
10Maximum Size Subarray Sum Equals kMedium
11Corporate Flight BookingsMedium—
12Maximum Population YearEasy—
13Left and Right Sum DifferencesVery easy
14Ways to Make a Fair ArrayMedium—
15Minimum Moves to Make Array ComplementaryMedium—

Practice in an AI round

Three of these are AI rounds: 30 minutes, an AI agent beside your code, then a scored report.

Practice Product of Array Except Self in an AI round