method
Prefix Sum — animated LeetCode walkthroughs
LeetCode problems solved with Prefix Sum. Browse the complete tag, then watch the algorithm move — step-by-step animation, Python and Go.
274 problems · 246 animated · 28 locked
Full Prefix sum index
- 209Minimum Size Subarray SumWatch
- 238Product of Array Except SelfWatch
- 253Meeting Rooms IILocked
- 303Range Sum Query - ImmutableWatch
- 304Range Sum Query 2D - ImmutableWatch
- 325Maximum Size Subarray Sum Equals kLocked
- 363Max Sum of Rectangle No Larger Than KWatch
- 370Range AdditionLocked
- 410Split Array Largest SumWatch
- 497Random Point in Non-overlapping RectanglesWatch
- 523Continuous Subarray SumWatch
- 525Contiguous ArrayWatch
- 528Random Pick with WeightWatch
- 548Split Array with Equal SumLocked
- 560Subarray Sum Equals KWatch
- 644Maximum Average Subarray IILocked
- 689Maximum Sum of 3 Non-Overlapping SubarraysWatch
- 713Subarray Product Less Than KWatch
- 724Find Pivot IndexWatch
- 731My Calendar IIWatch
- 732My Calendar IIIWatch
- 798Smallest Rotation with Highest ScoreWatch
- 813Largest Sum of AveragesWatch
- 848Shifting LettersWatch
- 862Shortest Subarray with Sum at Least KWatch
- 903Valid Permutations for DI SequenceWatch
- 930Binary Subarrays With SumWatch
- 974Subarray Sums Divisible by KWatch
- 995Minimum Number of K Consecutive Bit FlipsWatch
- 1000Minimum Cost to Merge StonesWatch
- 1004Max Consecutive Ones IIIWatch
- 1074Number of Submatrices That Sum to TargetWatch
- 1094Car PoolingWatch
- 1109Corporate Flight BookingsWatch
- 1124Longest Well-Performing IntervalWatch
- 1140Stone Game IIWatch
- 1177Can Make Palindrome from SubstringWatch
- 1208Get Equal Substrings Within BudgetWatch
- 1248Count Number of Nice SubarraysWatch
- 1292Maximum Side Length of a Square with Sum Less than or Equal to ThresholdWatch
- 1310XOR Queries of a SubarrayWatch
- 1314Matrix Block SumWatch
- 1352Product of the Last K NumbersWatch
- 1371Find the Longest Substring Containing Vowels in Even CountsWatch
- 1413Minimum Value to Get Positive Step by Step SumWatch
- 1420Build Array Where You Can Find The Maximum Exactly K ComparisonsWatch
- 1422Maximum Score After Splitting a StringWatch
- 1423Maximum Points You Can Obtain from CardsWatch
- 1442Count Triplets That Can Form Two Arrays of Equal XORWatch
- 1444Number of Ways of Cutting a PizzaWatch
- 1480Running Sum of 1d ArrayWatch
- 1508Range Sum of Sorted Subarray SumsWatch
- 1524Number of Sub-arrays With Odd SumWatch
- 1525Number of Good Ways to Split a StringWatch
- 1546Maximum Number of Non-Overlapping Subarrays With Sum Equals TargetWatch
- 1588Sum of All Odd Length SubarraysWatch
- 1589Maximum Sum Obtained of Any PermutationWatch
- 1590Make Sum Divisible by PWatch
- 1621Number of Sets of K Non-Overlapping Line SegmentsWatch
- 1658Minimum Operations to Reduce X to ZeroWatch
- 1664Ways to Make a Fair ArrayWatch
- 1674Minimum Moves to Make Array ComplementaryWatch
- 1685Sum of Absolute Differences in a Sorted ArrayWatch
- 1687Delivering Boxes from Storage to PortsWatch
- 1703Minimum Adjacent Swaps for K Consecutive OnesWatch
- 1712Ways to Split Array Into Three SubarraysWatch
- 1732Find the Highest AltitudeWatch
- 1737Change Minimum Characters to Satisfy One of Three ConditionsWatch
- 1738Find Kth Largest XOR Coordinate ValueWatch
- 1744Can You Eat Your Favorite Candy on Your Favorite Day?Watch
- 1769Minimum Number of Operations to Move All Balls to Each BoxWatch
- 1788Maximize the Beauty of the GardenLocked
- 1829Maximum XOR for Each QueryWatch
- 1838Frequency of the Most Frequent ElementWatch
- 1854Maximum Population YearWatch
- 1856Maximum Subarray Min-ProductWatch
- 1862Sum of Floored PairsWatch
- 1871Jump Game VIIWatch
- 1872Stone Game VIIIWatch
- 1878Get Biggest Three Rhombus Sums in a GridWatch
- 1889Minimum Space Wasted From PackagingWatch
- 1893Check if All the Integers in a Range Are CoveredWatch
- 1894Find the Student that Will Replace the ChalkWatch
- 1895Largest Magic SquareWatch
- 1906Minimum Absolute Difference QueriesWatch
- 1915Number of Wonderful SubstringsWatch
- 1930Unique Length-3 Palindromic SubsequencesWatch
- 1943Describe the PaintingWatch
- 1959Minimum Total Space Wasted With K Resizing OperationsWatch
- 1977Number of Ways to Separate NumbersWatch
- 1983Widest Pair of Indices With Equal Range SumLocked
- 1991Find the Middle Index in ArrayWatch
- 2015Average Height of Buildings in Each SegmentLocked
- 2017Grid GameWatch
- 2021Brightest Position on StreetLocked
- 2024Maximize the Confusion of an ExamWatch
- 2025Maximum Number of Ways to Partition an ArrayWatch
- 2055Plates Between CandlesWatch
- 2083Substrings That Begin and End With the Same LetterLocked
- 2100Find Good Days to Rob the BankWatch
- 2106Maximum Fruits Harvested After at Most K StepsWatch
- 2121Intervals Between Identical ElementsWatch
- 2132Stamping the GridWatch
- 2145Count the Hidden SequencesWatch
- 2171Removing Minimum Number of Magic BeansWatch
- 2207Maximize Number of Subsequences in a StringWatch
- 2209Minimum White Tiles After Covering With CarpetsWatch
- 2218Maximum Value of K Coins From PilesWatch
- 2219Maximum Sum Score of ArrayLocked
- 2222Number of Ways to Select BuildingsWatch
- 2234Maximum Total Beauty of the GardensWatch
- 2237Count Positions on Street With Required BrightnessLocked
- 2245Maximum Trailing Zeros in a Cornered PathWatch
- 2251Number of Flowers in Full BloomWatch
- 2256Minimum Average DifferenceWatch
- 2270Number of Ways to Split ArrayWatch
- 2271Maximum White Tiles Covered by a CarpetWatch
- 2281Sum of Total Strength of WizardsWatch
- 2302Count Subarrays With Score Less Than KWatch
- 2381Shifting Letters IIWatch
- 2382Maximum Segment Sum After RemovalsWatch
- 2389Longest Subsequence With Limited SumWatch
- 2391Minimum Amount of Time to Collect GarbageWatch
- 2398Maximum Number of Robots Within BudgetWatch
- 2406Divide Intervals Into Minimum Number of GroupsWatch
- 2420Find All Good IndicesWatch
- 2428Maximum Sum of an HourglassWatch
- 2438Range Product Queries of PowersWatch
- 2439Minimize Maximum of ArrayWatch
- 2448Minimum Cost to Make Array EqualWatch
- 2478Number of Beautiful PartitionsWatch
- 2483Minimum Penalty for a ShopWatch
- 2485Find the Pivot IntegerWatch
- 2488Count Subarrays With Median KWatch
- 2489Number of Substrings With Fixed RatioLocked
- 2505Bitwise OR of All Subsequence SumsLocked
- 2528Maximize the Minimum Powered CityWatch
- 2536Increment Submatrices by OneWatch
- 2552Count Increasing QuadrupletsWatch
- 2559Count Vowel Strings in RangesWatch
- 2574Left and Right Sum DifferencesWatch
- 2587Rearrange Array to Maximize Prefix ScoreWatch
- 2588Count the Number of Beautiful SubarraysWatch
- 2602Minimum Operations to Make All Array Elements EqualWatch
- 2615Sum of DistancesWatch
- 2640Find the Score of All Prefixes of an ArrayWatch
- 2680Maximum ORWatch
- 2681Power of HeroesWatch
- 2731Movement of RobotsWatch
- 2772Apply Operations to Make All Array Elements Equal to ZeroWatch
- 2819Minimum Relative Loss After Buying ChocolatesLocked
- 2838Maximum Coins Heroes Can CollectLocked
- 2845Count of Interesting SubarraysWatch
- 2848Points That Intersect With CarsWatch
- 2873Maximum Value of an Ordered Triplet IWatch
- 2874Maximum Value of an Ordered Triplet IIWatch
- 2875Minimum Size Subarray in Infinite ArrayWatch
- 2906Construct Product MatrixWatch
- 2909Minimum Sum of Mountain Triplets IIWatch
- 2945Find Maximum Non-decreasing Array LengthWatch
- 2947Count Beautiful Substrings IWatch
- 2949Count Beautiful Substrings IIWatch
- 2950Number of Divisible SubstringsLocked
- 2955Number of Same-End SubstringsLocked
- 2968Apply Operations to Maximize Frequency ScoreWatch
- 2971Find Polygon With the Largest PerimeterWatch
- 2983Palindrome Rearrangement QueriesWatch
- 3015Count the Number of Houses at a Certain Distance IWatch
- 3017Count the Number of Houses at a Certain Distance IIWatch
- 3026Maximum Good Subarray SumWatch
- 3028Ant on the BoundaryWatch
- 3070Count Submatrices with Top-Left Element and Sum Less Than kWatch
- 3077Maximum Strength of K Disjoint SubarraysWatch
- 3086Minimum Moves to Pick K OnesWatch
- 3096Minimum Levels to Gain More PointsWatch
- 3129Find All Possible Stable Binary Arrays IWatch
- 3130Find All Possible Stable Binary Arrays IIWatch
- 3147Taking Maximum Energy From the Mystic DungeonWatch
- 3152Special Array IIWatch
- 3179Find the N-th Value After K SecondsWatch
- 3191Minimum Operations to Make Binary Array Elements Equal to One IWatch
- 3212Count Submatrices With Equal Frequency of X and YWatch
- 3224Minimum Array Changes to Make Differences EqualWatch
- 3225Maximum Score From Grid OperationsWatch
- 3250Find the Count of Monotonic Pairs IWatch
- 3251Find the Count of Monotonic Pairs IIWatch
- 3261Count Substrings That Satisfy K-Constraint IIWatch
- 3279Maximum Total Area Occupied by PistonsLocked
- 3312Sorted GCD Pair QueriesWatch
- 3333Find the Original Typed String IIWatch
- 3346Maximum Frequency of an Element After Performing Operations IWatch
- 3347Maximum Frequency of an Element After Performing Operations IIWatch
- 3354Make Array Elements Equal to ZeroWatch
- 3355Zero Array Transformation IWatch
- 3356Zero Array Transformation IIWatch
- 3361Shift Distance Between Two StringsWatch
- 3362Zero Array Transformation IIIWatch
- 3364Minimum Positive Sum Subarray Watch
- 3381Maximum Subarray Sum With Length Divisible by KWatch
- 3410Maximize Subarray Sum After Removing All Occurrences of One ElementWatch
- 3413Maximum Coins From K Consecutive BagsWatch
- 3425Longest Special PathWatch
- 3427Sum of Variable Length SubarraysWatch
- 3432Count Partitions with Even Sum DifferenceWatch
- 3434Maximum Frequency After Subarray OperationWatch
- 3445Maximum Difference Between Even and Odd Frequency IIWatch
- 3473Sum of K Subarrays With Length at Least MWatch
- 3480Maximize Subarrays After Removing One Conflicting PairWatch
- 3486Longest Special Path IIWatch
- 3494Find the Minimum Amount of Time to Brew PotionsWatch
- 3500Minimum Cost to Divide Array Into SubarraysWatch
- 3511Make a Positive ArrayLocked
- 3538Merge Operations for Minimum Travel TimeWatch
- 3540Minimum Time to Visit All HousesLocked
- 3546Equal Sum Grid Partition IWatch
- 3548Equal Sum Grid Partition IIWatch
- 3578Count Partitions With Max-Min Difference at Most KWatch
- 3599Partition Array to Minimize XORWatch
- 3628Maximum Number of Subsequences After One InsertingWatch
- 3632Subarrays with XOR at Least KLocked
- 3636Threshold Majority QueriesWatch
- 3652Best Time to Buy and Sell Stock using StrategyWatch
- 3653XOR After Range Multiplication Queries IWatch
- 3654Minimum Sum After Divisible Sum DeletionsWatch
- 3655XOR After Range Multiplication Queries IIWatch
- 3656Determine if a Simple Graph ExistsLocked
- 3694Distinct Points Reachable After Substring RemovalWatch
- 3698Split Array With Minimum DifferenceWatch
- 3699Number of ZigZag Arrays IWatch
- 3707Equal Score SubstringsWatch
- 3709Design Exam Scores TrackerWatch
- 3714Longest Balanced Substring IIWatch
- 3719Longest Balanced Subarray IWatch
- 3721Longest Balanced Subarray IIWatch
- 3728Stable Subarrays With Equal Boundary and Interior SumWatch
- 3729Count Distinct Subarrays Divisible by K in Sorted ArrayWatch
- 3737Count Subarrays With Majority Element IWatch
- 3739Count Subarrays With Majority Element IIWatch
- 3748Count Stable SubarraysWatch
- 3755Find Maximum Balanced XOR Subarray LengthWatch
- 3756Concatenate Non-Zero Digits and Multiply by Sum IIWatch
- 3771Total Score of Dungeon RunsWatch
- 3788Maximum Score of a SplitWatch
- 3797Count Routes to Climb a Rectangular GridWatch
- 3826Minimum Partition ScoreWatch
- 3845Maximum Subarray XOR with Bounded RangeWatch
- 3862Find the Smallest Balanced IndexWatch
- 3864Minimum Cost to Partition a Binary StringWatch
- 3883Count Non Decreasing Arrays With Given Digit SumsWatch
- 3888Minimum Operations to Make All Grid Elements EqualLocked
- 3891Minimum Increase to Maximize Special IndicesWatch
- 3900Longest Balanced Substring After One SwapWatch
- 3903Smallest Stable Index IWatch
- 3904Smallest Stable Index IIWatch
- 3916Number of ZigZag Arrays IIILocked
- 3919Minimum Cost to Move Between IndicesWatch
- 3929Minimum Partition Score IILocked
- 3933Largest Local Values in a Matrix IIWatch
- 3938Maximum Path Intersection Sum in a GridWatch
- 3956Maximum Sum of M Non-Overlapping Subarrays IWatch
- 3957Maximum Sum of M Non-Overlapping Subarrays IIWatch
- 3964Minimum Lights to Illuminate a RoadWatch
- 3969Valid Subarrays With Matching Sum Digits IWatch
- 3972Valid Subarrays With Matching Sum Digits IILocked
- 3981Count Distinct Ways to Form Target from Two StringsWatch
- 3985Palindromic Subarray SumWatch
- 4008Minimum Initial Strength to Defeat All MonstersWatch
- 4011Count Subarrays With Even Odd Ratio IWatch
- 4012Count of Unfinished Tasks After Each ShiftWatch
- 4013Count Subarrays With Even Odd Ratio IIWatch
- 4033Valid K-Unique Subarrays IWatch
- 4042Valid K-Unique Subarrays IILocked
- 4044Count Good Cyclic RotationsWatch
- 4051Count Subarrays with Distant SumsWatch