Skip to content
Use code for 50% offSee plans

Prefix Sum Problems

186 Prefix Sum LeetCode problems · Solve with AI-powered hints & step-by-step explanations.

Learn the coding interview patterns behind these problems.

Start with these

All Prefix Sum problems

209 Minimum Size Subarray Sum Medium238 Product of Array Except Self Medium303 Range Sum Query - Immutable Easy304 Range Sum Query 2D - Immutable Medium363 Max Sum of Rectangle No Larger Than K Hard410 Split Array Largest Sum Hard497 Random Point in Non-overlapping Rectangles Medium523 Continuous Subarray Sum Medium525 Contiguous Array Medium528 Random Pick with Weight Medium560 Subarray Sum Equals K Medium689 Maximum Sum of 3 Non-Overlapping Subarrays Hard713 Subarray Product Less Than K Medium724 Find Pivot Index Easy731 My Calendar II Medium732 My Calendar III Hard798 Smallest Rotation with Highest Score Hard813 Largest Sum of Averages Medium848 Shifting Letters Medium862 Shortest Subarray with Sum at Least K Hard903 Valid Permutations for DI Sequence Hard930 Binary Subarrays With Sum Medium974 Subarray Sums Divisible by K Medium995 Minimum Number of K Consecutive Bit Flips Hard1000 Minimum Cost to Merge Stones Hard1004 Max Consecutive Ones III Medium1074 Number of Submatrices That Sum to Target Hard1094 Car Pooling Medium1109 Corporate Flight Bookings Medium1124 Longest Well-Performing Interval Medium1140 Stone Game II Medium1177 Can Make Palindrome from Substring Medium1208 Get Equal Substrings Within Budget Medium1248 Count Number of Nice Subarrays Medium1292 Maximum Side Length of a Square with Sum Less than or Equal to Threshold Medium1310 XOR Queries of a Subarray Medium1314 Matrix Block Sum Medium1352 Product of the Last K Numbers Medium1371 Find the Longest Substring Containing Vowels in Even Counts Medium1413 Minimum Value to Get Positive Step by Step Sum Easy1420 Build Array Where You Can Find The Maximum Exactly K Comparisons Hard1422 Maximum Score After Splitting a String Easy1423 Maximum Points You Can Obtain from Cards Medium1442 Count Triplets That Can Form Two Arrays of Equal XOR Medium1444 Number of Ways of Cutting a Pizza Hard1480 Running Sum of 1d Array Easy1508 Range Sum of Sorted Subarray Sums Medium1524 Number of Sub-arrays With Odd Sum Medium1546 Maximum Number of Non-Overlapping Subarrays With Sum Equals Target Medium1588 Sum of All Odd Length Subarrays Easy1589 Maximum Sum Obtained of Any Permutation Medium1590 Make Sum Divisible by P Medium1658 Minimum Operations to Reduce X to Zero Medium1664 Ways to Make a Fair Array Medium1674 Minimum Moves to Make Array Complementary Medium1685 Sum of Absolute Differences in a Sorted Array Medium1687 Delivering Boxes from Storage to Ports Hard1703 Minimum Adjacent Swaps for K Consecutive Ones Hard1712 Ways to Split Array Into Three Subarrays Medium1732 Find the Highest Altitude Easy1737 Change Minimum Characters to Satisfy One of Three Conditions Medium1738 Find Kth Largest XOR Coordinate Value Medium1744 Can You Eat Your Favorite Candy on Your Favorite Day? Medium1769 Minimum Number of Operations to Move All Balls to Each Box Medium1829 Maximum XOR for Each Query Medium1838 Frequency of the Most Frequent Element Medium1854 Maximum Population Year Easy1856 Maximum Subarray Min-Product Medium1862 Sum of Floored Pairs Hard1871 Jump Game VII Medium1872 Stone Game VIII Hard1878 Get Biggest Three Rhombus Sums in a Grid Medium1889 Minimum Space Wasted From Packaging Hard1893 Check if All the Integers in a Range Are Covered Easy1894 Find the Student that Will Replace the Chalk Medium1895 Largest Magic Square Medium1915 Number of Wonderful Substrings Medium1930 Unique Length-3 Palindromic Subsequences Medium1943 Describe the Painting Medium1991 Find the Middle Index in Array Easy2017 Grid Game Medium2024 Maximize the Confusion of an Exam Medium2025 Maximum Number of Ways to Partition an Array Hard2055 Plates Between Candles Medium2100 Find Good Days to Rob the Bank Medium2106 Maximum Fruits Harvested After at Most K Steps Hard2121 Intervals Between Identical Elements Medium2132 Stamping the Grid Hard2145 Count the Hidden Sequences Medium2171 Removing Minimum Number of Magic Beans Medium2207 Maximize Number of Subsequences in a String Medium2209 Minimum White Tiles After Covering With Carpets Hard2218 Maximum Value of K Coins From Piles Hard2222 Number of Ways to Select Buildings Medium2234 Maximum Total Beauty of the Gardens Hard2245 Maximum Trailing Zeros in a Cornered Path Medium2251 Number of Flowers in Full Bloom Hard2256 Minimum Average Difference Medium2270 Number of Ways to Split Array Medium2271 Maximum White Tiles Covered by a Carpet Medium2281 Sum of Total Strength of Wizards Hard2302 Count Subarrays With Score Less Than K Hard2381 Shifting Letters II Medium2382 Maximum Segment Sum After Removals Hard2389 Longest Subsequence With Limited Sum Easy2391 Minimum Amount of Time to Collect Garbage Medium2398 Maximum Number of Robots Within Budget Hard2406 Divide Intervals Into Minimum Number of Groups Medium2420 Find All Good Indices Medium2428 Maximum Sum of an Hourglass Medium2438 Range Product Queries of Powers Medium2439 Minimize Maximum of Array Medium2448 Minimum Cost to Make Array Equal Hard2483 Minimum Penalty for a Shop Medium2485 Find the Pivot Integer Easy2488 Count Subarrays With Median K Hard2528 Maximize the Minimum Powered City Hard2536 Increment Submatrices by One Medium2552 Count Increasing Quadruplets Hard2559 Count Vowel Strings in Ranges Medium2574 Left and Right Sum Differences Easy2587 Rearrange Array to Maximize Prefix Score Medium2588 Count the Number of Beautiful Subarrays Medium2602 Minimum Operations to Make All Array Elements Equal Medium2615 Sum of Distances Medium2640 Find the Score of All Prefixes of an Array Medium2680 Maximum OR Medium2681 Power of Heroes Hard2731 Movement of Robots Medium2772 Apply Operations to Make All Array Elements Equal to Zero Medium2845 Count of Interesting Subarrays Medium2848 Points That Intersect With Cars Easy2875 Minimum Size Subarray in Infinite Array Medium2906 Construct Product Matrix Medium2947 Count Beautiful Substrings I Medium2949 Count Beautiful Substrings II Hard2968 Apply Operations to Maximize Frequency Score Hard2971 Find Polygon With the Largest Perimeter Medium2983 Palindrome Rearrangement Queries Hard3015 Count the Number of Houses at a Certain Distance I Medium3017 Count the Number of Houses at a Certain Distance II Hard3026 Maximum Good Subarray Sum Medium3028 Ant on the Boundary Easy3070 Count Submatrices with Top-Left Element and Sum Less Than k Medium3077 Maximum Strength of K Disjoint Subarrays Hard3086 Minimum Moves to Pick K Ones Hard3096 Minimum Levels to Gain More Points Medium3129 Find All Possible Stable Binary Arrays I Medium3130 Find All Possible Stable Binary Arrays II Hard3147 Taking Maximum Energy From the Mystic Dungeon Medium3152 Special Array II Medium3179 Find the N-th Value After K Seconds Medium3191 Minimum Operations to Make Binary Array Elements Equal to One I Medium3212 Count Submatrices With Equal Frequency of X and Y Medium3224 Minimum Array Changes to Make Differences Equal Medium3225 Maximum Score From Grid Operations Hard3250 Find the Count of Monotonic Pairs I Hard3251 Find the Count of Monotonic Pairs II Hard3261 Count Substrings That Satisfy K-Constraint II Hard3312 Sorted GCD Pair Queries Hard3333 Find the Original Typed String II Hard3346 Maximum Frequency of an Element After Performing Operations I Medium3347 Maximum Frequency of an Element After Performing Operations II Hard3354 Make Array Elements Equal to Zero Easy3355 Zero Array Transformation I Medium3356 Zero Array Transformation II Medium3361 Shift Distance Between Two Strings Medium3362 Zero Array Transformation III Medium3364 Minimum Positive Sum Subarray Easy3381 Maximum Subarray Sum With Length Divisible by K Medium3413 Maximum Coins From K Consecutive Bags Medium3425 Longest Special Path Hard3427 Sum of Variable Length Subarrays Easy3432 Count Partitions with Even Sum Difference Easy3434 Maximum Frequency After Subarray Operation Medium3445 Maximum Difference Between Even and Odd Frequency II Hard3473 Sum of K Subarrays With Length at Least M Medium3480 Maximize Subarrays After Removing One Conflicting Pair Hard3486 Longest Special Path II Hard3494 Find the Minimum Amount of Time to Brew Potions Medium3500 Minimum Cost to Divide Array Into Subarrays Hard3538 Merge Operations for Minimum Travel Time Hard3546 Equal Sum Grid Partition I Medium3548 Equal Sum Grid Partition II Hard3578 Count Partitions With Max-Min Difference at Most K Medium3599 Partition Array to Minimize XOR Medium