Skip to content
LEETFLIX

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

  1. 209Minimum Size Subarray SumWatch
  2. 238Product of Array Except SelfWatch
  3. 253Meeting Rooms IILocked
  4. 303Range Sum Query - ImmutableWatch
  5. 304Range Sum Query 2D - ImmutableWatch
  6. 325Maximum Size Subarray Sum Equals kLocked
  7. 363Max Sum of Rectangle No Larger Than KWatch
  8. 370Range AdditionLocked
  9. 410Split Array Largest SumWatch
  10. 497Random Point in Non-overlapping RectanglesWatch
  11. 523Continuous Subarray SumWatch
  12. 525Contiguous ArrayWatch
  13. 528Random Pick with WeightWatch
  14. 548Split Array with Equal SumLocked
  15. 560Subarray Sum Equals KWatch
  16. 644Maximum Average Subarray IILocked
  17. 689Maximum Sum of 3 Non-Overlapping SubarraysWatch
  18. 713Subarray Product Less Than KWatch
  19. 724Find Pivot IndexWatch
  20. 731My Calendar IIWatch
  21. 732My Calendar IIIWatch
  22. 798Smallest Rotation with Highest ScoreWatch
  23. 813Largest Sum of AveragesWatch
  24. 848Shifting LettersWatch
  25. 862Shortest Subarray with Sum at Least KWatch
  26. 903Valid Permutations for DI SequenceWatch
  27. 930Binary Subarrays With SumWatch
  28. 974Subarray Sums Divisible by KWatch
  29. 995Minimum Number of K Consecutive Bit FlipsWatch
  30. 1000Minimum Cost to Merge StonesWatch
  31. 1004Max Consecutive Ones IIIWatch
  32. 1074Number of Submatrices That Sum to TargetWatch
  33. 1094Car PoolingWatch
  34. 1109Corporate Flight BookingsWatch
  35. 1124Longest Well-Performing IntervalWatch
  36. 1140Stone Game IIWatch
  37. 1177Can Make Palindrome from SubstringWatch
  38. 1208Get Equal Substrings Within BudgetWatch
  39. 1248Count Number of Nice SubarraysWatch
  40. 1292Maximum Side Length of a Square with Sum Less than or Equal to ThresholdWatch
  41. 1310XOR Queries of a SubarrayWatch
  42. 1314Matrix Block SumWatch
  43. 1352Product of the Last K NumbersWatch
  44. 1371Find the Longest Substring Containing Vowels in Even CountsWatch
  45. 1413Minimum Value to Get Positive Step by Step SumWatch
  46. 1420Build Array Where You Can Find The Maximum Exactly K ComparisonsWatch
  47. 1422Maximum Score After Splitting a StringWatch
  48. 1423Maximum Points You Can Obtain from CardsWatch
  49. 1442Count Triplets That Can Form Two Arrays of Equal XORWatch
  50. 1444Number of Ways of Cutting a PizzaWatch
  51. 1480Running Sum of 1d ArrayWatch
  52. 1508Range Sum of Sorted Subarray SumsWatch
  53. 1524Number of Sub-arrays With Odd SumWatch
  54. 1525Number of Good Ways to Split a StringWatch
  55. 1546Maximum Number of Non-Overlapping Subarrays With Sum Equals TargetWatch
  56. 1588Sum of All Odd Length SubarraysWatch
  57. 1589Maximum Sum Obtained of Any PermutationWatch
  58. 1590Make Sum Divisible by PWatch
  59. 1621Number of Sets of K Non-Overlapping Line SegmentsWatch
  60. 1658Minimum Operations to Reduce X to ZeroWatch
  61. 1664Ways to Make a Fair ArrayWatch
  62. 1674Minimum Moves to Make Array ComplementaryWatch
  63. 1685Sum of Absolute Differences in a Sorted ArrayWatch
  64. 1687Delivering Boxes from Storage to PortsWatch
  65. 1703Minimum Adjacent Swaps for K Consecutive OnesWatch
  66. 1712Ways to Split Array Into Three SubarraysWatch
  67. 1732Find the Highest AltitudeWatch
  68. 1737Change Minimum Characters to Satisfy One of Three ConditionsWatch
  69. 1738Find Kth Largest XOR Coordinate ValueWatch
  70. 1744Can You Eat Your Favorite Candy on Your Favorite Day?Watch
  71. 1769Minimum Number of Operations to Move All Balls to Each BoxWatch
  72. 1788Maximize the Beauty of the GardenLocked
  73. 1829Maximum XOR for Each QueryWatch
  74. 1838Frequency of the Most Frequent ElementWatch
  75. 1854Maximum Population YearWatch
  76. 1856Maximum Subarray Min-ProductWatch
  77. 1862Sum of Floored PairsWatch
  78. 1871Jump Game VIIWatch
  79. 1872Stone Game VIIIWatch
  80. 1878Get Biggest Three Rhombus Sums in a GridWatch
  81. 1889Minimum Space Wasted From PackagingWatch
  82. 1893Check if All the Integers in a Range Are CoveredWatch
  83. 1894Find the Student that Will Replace the ChalkWatch
  84. 1895Largest Magic SquareWatch
  85. 1906Minimum Absolute Difference QueriesWatch
  86. 1915Number of Wonderful SubstringsWatch
  87. 1930Unique Length-3 Palindromic SubsequencesWatch
  88. 1943Describe the PaintingWatch
  89. 1959Minimum Total Space Wasted With K Resizing OperationsWatch
  90. 1977Number of Ways to Separate NumbersWatch
  91. 1983Widest Pair of Indices With Equal Range SumLocked
  92. 1991Find the Middle Index in ArrayWatch
  93. 2015Average Height of Buildings in Each SegmentLocked
  94. 2017Grid GameWatch
  95. 2021Brightest Position on StreetLocked
  96. 2024Maximize the Confusion of an ExamWatch
  97. 2025Maximum Number of Ways to Partition an ArrayWatch
  98. 2055Plates Between CandlesWatch
  99. 2083Substrings That Begin and End With the Same LetterLocked
  100. 2100Find Good Days to Rob the BankWatch
  101. 2106Maximum Fruits Harvested After at Most K StepsWatch
  102. 2121Intervals Between Identical ElementsWatch
  103. 2132Stamping the GridWatch
  104. 2145Count the Hidden SequencesWatch
  105. 2171Removing Minimum Number of Magic BeansWatch
  106. 2207Maximize Number of Subsequences in a StringWatch
  107. 2209Minimum White Tiles After Covering With CarpetsWatch
  108. 2218Maximum Value of K Coins From PilesWatch
  109. 2219Maximum Sum Score of ArrayLocked
  110. 2222Number of Ways to Select BuildingsWatch
  111. 2234Maximum Total Beauty of the GardensWatch
  112. 2237Count Positions on Street With Required BrightnessLocked
  113. 2245Maximum Trailing Zeros in a Cornered PathWatch
  114. 2251Number of Flowers in Full BloomWatch
  115. 2256Minimum Average DifferenceWatch
  116. 2270Number of Ways to Split ArrayWatch
  117. 2271Maximum White Tiles Covered by a CarpetWatch
  118. 2281Sum of Total Strength of WizardsWatch
  119. 2302Count Subarrays With Score Less Than KWatch
  120. 2381Shifting Letters IIWatch
  121. 2382Maximum Segment Sum After RemovalsWatch
  122. 2389Longest Subsequence With Limited SumWatch
  123. 2391Minimum Amount of Time to Collect GarbageWatch
  124. 2398Maximum Number of Robots Within BudgetWatch
  125. 2406Divide Intervals Into Minimum Number of GroupsWatch
  126. 2420Find All Good IndicesWatch
  127. 2428Maximum Sum of an HourglassWatch
  128. 2438Range Product Queries of PowersWatch
  129. 2439Minimize Maximum of ArrayWatch
  130. 2448Minimum Cost to Make Array EqualWatch
  131. 2478Number of Beautiful PartitionsWatch
  132. 2483Minimum Penalty for a ShopWatch
  133. 2485Find the Pivot IntegerWatch
  134. 2488Count Subarrays With Median KWatch
  135. 2489Number of Substrings With Fixed RatioLocked
  136. 2505Bitwise OR of All Subsequence SumsLocked
  137. 2528Maximize the Minimum Powered CityWatch
  138. 2536Increment Submatrices by OneWatch
  139. 2552Count Increasing QuadrupletsWatch
  140. 2559Count Vowel Strings in RangesWatch
  141. 2574Left and Right Sum DifferencesWatch
  142. 2587Rearrange Array to Maximize Prefix ScoreWatch
  143. 2588Count the Number of Beautiful SubarraysWatch
  144. 2602Minimum Operations to Make All Array Elements EqualWatch
  145. 2615Sum of DistancesWatch
  146. 2640Find the Score of All Prefixes of an ArrayWatch
  147. 2680Maximum ORWatch
  148. 2681Power of HeroesWatch
  149. 2731Movement of RobotsWatch
  150. 2772Apply Operations to Make All Array Elements Equal to ZeroWatch
  151. 2819Minimum Relative Loss After Buying ChocolatesLocked
  152. 2838Maximum Coins Heroes Can CollectLocked
  153. 2845Count of Interesting SubarraysWatch
  154. 2848Points That Intersect With CarsWatch
  155. 2873Maximum Value of an Ordered Triplet IWatch
  156. 2874Maximum Value of an Ordered Triplet IIWatch
  157. 2875Minimum Size Subarray in Infinite ArrayWatch
  158. 2906Construct Product MatrixWatch
  159. 2909Minimum Sum of Mountain Triplets IIWatch
  160. 2945Find Maximum Non-decreasing Array LengthWatch
  161. 2947Count Beautiful Substrings IWatch
  162. 2949Count Beautiful Substrings IIWatch
  163. 2950Number of Divisible SubstringsLocked
  164. 2955Number of Same-End SubstringsLocked
  165. 2968Apply Operations to Maximize Frequency ScoreWatch
  166. 2971Find Polygon With the Largest PerimeterWatch
  167. 2983Palindrome Rearrangement QueriesWatch
  168. 3015Count the Number of Houses at a Certain Distance IWatch
  169. 3017Count the Number of Houses at a Certain Distance IIWatch
  170. 3026Maximum Good Subarray SumWatch
  171. 3028Ant on the BoundaryWatch
  172. 3070Count Submatrices with Top-Left Element and Sum Less Than kWatch
  173. 3077Maximum Strength of K Disjoint SubarraysWatch
  174. 3086Minimum Moves to Pick K OnesWatch
  175. 3096Minimum Levels to Gain More PointsWatch
  176. 3129Find All Possible Stable Binary Arrays IWatch
  177. 3130Find All Possible Stable Binary Arrays IIWatch
  178. 3147Taking Maximum Energy From the Mystic DungeonWatch
  179. 3152Special Array IIWatch
  180. 3179Find the N-th Value After K SecondsWatch
  181. 3191Minimum Operations to Make Binary Array Elements Equal to One IWatch
  182. 3212Count Submatrices With Equal Frequency of X and YWatch
  183. 3224Minimum Array Changes to Make Differences EqualWatch
  184. 3225Maximum Score From Grid OperationsWatch
  185. 3250Find the Count of Monotonic Pairs IWatch
  186. 3251Find the Count of Monotonic Pairs IIWatch
  187. 3261Count Substrings That Satisfy K-Constraint IIWatch
  188. 3279Maximum Total Area Occupied by PistonsLocked
  189. 3312Sorted GCD Pair QueriesWatch
  190. 3333Find the Original Typed String IIWatch
  191. 3346Maximum Frequency of an Element After Performing Operations IWatch
  192. 3347Maximum Frequency of an Element After Performing Operations IIWatch
  193. 3354Make Array Elements Equal to ZeroWatch
  194. 3355Zero Array Transformation IWatch
  195. 3356Zero Array Transformation IIWatch
  196. 3361Shift Distance Between Two StringsWatch
  197. 3362Zero Array Transformation IIIWatch
  198. 3364Minimum Positive Sum Subarray Watch
  199. 3381Maximum Subarray Sum With Length Divisible by KWatch
  200. 3410Maximize Subarray Sum After Removing All Occurrences of One ElementWatch
  201. 3413Maximum Coins From K Consecutive BagsWatch
  202. 3425Longest Special PathWatch
  203. 3427Sum of Variable Length SubarraysWatch
  204. 3432Count Partitions with Even Sum DifferenceWatch
  205. 3434Maximum Frequency After Subarray OperationWatch
  206. 3445Maximum Difference Between Even and Odd Frequency IIWatch
  207. 3473Sum of K Subarrays With Length at Least MWatch
  208. 3480Maximize Subarrays After Removing One Conflicting PairWatch
  209. 3486Longest Special Path IIWatch
  210. 3494Find the Minimum Amount of Time to Brew PotionsWatch
  211. 3500Minimum Cost to Divide Array Into SubarraysWatch
  212. 3511Make a Positive ArrayLocked
  213. 3538Merge Operations for Minimum Travel TimeWatch
  214. 3540Minimum Time to Visit All HousesLocked
  215. 3546Equal Sum Grid Partition IWatch
  216. 3548Equal Sum Grid Partition IIWatch
  217. 3578Count Partitions With Max-Min Difference at Most KWatch
  218. 3599Partition Array to Minimize XORWatch
  219. 3628Maximum Number of Subsequences After One InsertingWatch
  220. 3632Subarrays with XOR at Least KLocked
  221. 3636Threshold Majority QueriesWatch
  222. 3652Best Time to Buy and Sell Stock using StrategyWatch
  223. 3653XOR After Range Multiplication Queries IWatch
  224. 3654Minimum Sum After Divisible Sum DeletionsWatch
  225. 3655XOR After Range Multiplication Queries IIWatch
  226. 3656Determine if a Simple Graph ExistsLocked
  227. 3694Distinct Points Reachable After Substring RemovalWatch
  228. 3698Split Array With Minimum DifferenceWatch
  229. 3699Number of ZigZag Arrays IWatch
  230. 3707Equal Score SubstringsWatch
  231. 3709Design Exam Scores TrackerWatch
  232. 3714Longest Balanced Substring IIWatch
  233. 3719Longest Balanced Subarray IWatch
  234. 3721Longest Balanced Subarray IIWatch
  235. 3728Stable Subarrays With Equal Boundary and Interior SumWatch
  236. 3729Count Distinct Subarrays Divisible by K in Sorted ArrayWatch
  237. 3737Count Subarrays With Majority Element IWatch
  238. 3739Count Subarrays With Majority Element IIWatch
  239. 3748Count Stable SubarraysWatch
  240. 3755Find Maximum Balanced XOR Subarray LengthWatch
  241. 3756Concatenate Non-Zero Digits and Multiply by Sum IIWatch
  242. 3771Total Score of Dungeon RunsWatch
  243. 3788Maximum Score of a SplitWatch
  244. 3797Count Routes to Climb a Rectangular GridWatch
  245. 3826Minimum Partition ScoreWatch
  246. 3845Maximum Subarray XOR with Bounded RangeWatch
  247. 3862Find the Smallest Balanced IndexWatch
  248. 3864Minimum Cost to Partition a Binary StringWatch
  249. 3883Count Non Decreasing Arrays With Given Digit SumsWatch
  250. 3888Minimum Operations to Make All Grid Elements EqualLocked
  251. 3891Minimum Increase to Maximize Special IndicesWatch
  252. 3900Longest Balanced Substring After One SwapWatch
  253. 3903Smallest Stable Index IWatch
  254. 3904Smallest Stable Index IIWatch
  255. 3916Number of ZigZag Arrays IIILocked
  256. 3919Minimum Cost to Move Between IndicesWatch
  257. 3929Minimum Partition Score IILocked
  258. 3933Largest Local Values in a Matrix IIWatch
  259. 3938Maximum Path Intersection Sum in a GridWatch
  260. 3956Maximum Sum of M Non-Overlapping Subarrays IWatch
  261. 3957Maximum Sum of M Non-Overlapping Subarrays IIWatch
  262. 3964Minimum Lights to Illuminate a RoadWatch
  263. 3969Valid Subarrays With Matching Sum Digits IWatch
  264. 3972Valid Subarrays With Matching Sum Digits IILocked
  265. 3981Count Distinct Ways to Form Target from Two StringsWatch
  266. 3985Palindromic Subarray SumWatch
  267. 4008Minimum Initial Strength to Defeat All MonstersWatch
  268. 4011Count Subarrays With Even Odd Ratio IWatch
  269. 4012Count of Unfinished Tasks After Each ShiftWatch
  270. 4013Count Subarrays With Even Odd Ratio IIWatch
  271. 4033Valid K-Unique Subarrays IWatch
  272. 4042Valid K-Unique Subarrays IILocked
  273. 4044Count Good Cyclic RotationsWatch
  274. 4051Count Subarrays with Distant SumsWatch