Prefix Sum & Hash Map
FundamentalsO(1) range queries and subarray sum lookups using cumulative totals
205 problems·17 Easy·131 Medium·57 Hard
Pattern Study Guide & Cheat Sheet▼
Precompute cumulative values so any range sum sum(nums[i..j]) is computed in O(1) time as prefix[j+1] - prefix[i], or combined with a Hash Map to find subarrays in O(N).
Core Invariant: Sum(i..j) = Prefix[j] - Prefix[i-1] = target implies Prefix[i-1] = Prefix[j] - target. By storing seen prefix sums in a Hash Map, we can count or find valid starting indices in O(1)!
Recognize it (Keywords & Signals)
- Subarray sum equals K (especially with negative numbers)
- Number of continuous subarrays divisible by K
- Longest subarray with equal number of 0s and 1s
- Repeated range sum queries on static array / 2D matrix
When NOT to use
Frequent updates/modifications to array elements (use Fenwick Tree / Segment Tree for O(log n) dynamic updates).
How to solve (Step-by-step)
- 1.Initialize `curr_sum = 0`, `count = 0`, and `seen = {0: 1}` (empty prefix has sum 0 occurring once).
- 2.Iterate through each number `x` in the array.
- 3.Add to running sum: `curr_sum += x`.
- 4.Check if `(curr_sum - target)` exists in `seen`. If so, add its frequency to `count`.
- 5.Record current sum in map: `seen[curr_sum] = seen.get(curr_sum, 0) + 1`.
- 6.Return `count`.
Watch for (Interview Traps)
- Forgetting `{0: 1}` in the hash map (fails on valid subarrays starting from index 0)
- Updating the hash map BEFORE checking `curr_sum - k` (can cause self-match when k = 0)
- Mistakenly using Sliding Window when numbers can be negative (Sliding Window requires monotonic sums)
Prefix Sum + Hash Map (Subarray Sum Equals K)
def subarray_sum_equals_k(nums: list[int], k: int) -> int:
prefix_counts = {0: 1} # Base case: sum 0 occurs once before array starts
curr_sum = 0
total_subarrays = 0
for num in nums:
curr_sum += num
# If (curr_sum - k) was seen before, those prior points form valid subarrays
diff = curr_sum - k
if diff in prefix_counts:
total_subarrays += prefix_counts[diff]
prefix_counts[curr_sum] = prefix_counts.get(curr_sum, 0) + 1
return total_subarrays- Cost
- O(n) single pass · O(n) for hash map / prefix array (Reduces an O(n^2) brute force subarray check down to O(n).)
Canonical problems
#560 Subarray Sum Equals K: Count subarrays with sum K even with negative numbers
#525 Contiguous Array: Map 0 -> -1; longest subarray with sum 0 has equal 0s and 1s
#238 Product of Array Except Self: Combine prefix products from left and suffix products from right
#304 Range Sum Query 2D - Immutable: 2D prefix grid inclusion-exclusion area formula
⌘K
Medium·44 companies·Max freq 100%·Acc 69.1%
ThousandEyesAsanaQuantcast+41
Medium·22 companies·Max freq 100%·Acc 54.7%
YatraSquarepoint CapitalSamsung+19
Medium·12 companies·Max freq 100%·Acc 45.0%
Pony.aiPony.aiUrban Company+9
Medium·11 companies·Max freq 100%·Acc 63.0%
StarbucksTargetTekion+8
Medium·11 companies·Max freq 100%·Acc 58.0%
FlipkartPhonePeSprinklr+8
Medium·11 companies·Max freq 70%·Acc 56.5%
HashedInTikTokJPMorgan Chase+8
Easy·10 companies·Max freq 100%·Acc 64.8%
SwiggyDellYelp+7
Hard·8 companies·Max freq 100%·Acc 32.9%
DevRevPhonePeGoldman Sachs+5
Medium·8 companies·Max freq 63%·Acc 50.9%
PalantirMetaGoldman Sachs+5
Medium·7 companies·Max freq 100%·Acc 67.3%
DunzoFlatiron HealthPhonePe+4
Medium·7 companies·Max freq 88%·Acc 63.6%
AdobeWalmart LabsIBM+4
Medium·6 companies·Max freq 100%·Acc 55.7%
DirectiMicrosoftAmazon+3
Hard·6 companies·Max freq 100%·Acc 48.6%
Fractal AnalyticsMicrosoftMeta+3
Hard·6 companies·Max freq 63%·Acc 59.9%
General MotorsMetaGoogle+3
Medium·6 companies·Max freq 50%·Acc 80.4%
UberMicrosoftGoogle+3
Medium·6 companies·Max freq 50%·Acc 62.7%
Goldman SachsGoogleBloomberg+3
Medium·6 companies·Max freq 39%·Acc 73.8%
VisaGoogleAmazon+3
Medium·6 companies·Max freq 38%·Acc 90.2%
GoogleMetaTikTok+3
Medium·6 companies·Max freq 38%·Acc 75.6%
MicrosoftGoldman SachsBloomberg+3
Medium·5 companies·Max freq 100%·Acc 64.9%
CureFitMicrosoftAmazon+2
#3152Special Array II
Medium·5 companies·Max freq 100%·Acc 0.5%
National Payments Corporation of IndiaNational Payments Corporation of IndiaAmazon+2
Hard·5 companies·Max freq 77%·Acc 62.2%
PinterestGoogleMicrosoft+2
Medium·5 companies·Max freq 68%·Acc 61.2%
TrilogyGoldman SachsGoogle+2
Easy·5 companies·Max freq 63%·Acc 85.3%
AccentureAmazonBloomberg+2
Hard·5 companies·Max freq 55%·Acc 64.5%
LinkedInAmazonGoogle+2
Hard·5 companies·Max freq 55%·Acc 74.6%
SnapSnapAmazon+2
Medium·5 companies·Max freq 50%·Acc 59.7%
UberVisaMeta+2
Medium·5 companies·Max freq 50%·Acc 67.9%
Goldman SachsPinterestGoogle+2
Medium·5 companies·Max freq 25%·Acc 75.7%
MicrosoftAmazonMeta+2
Hard·5 companies·Max freq 18%·Acc 45.5%
GoogleMicrosoftAmazon+2
Medium·4 companies·Max freq 100%·Acc 65.4%
IMCFractal AnalyticsGoogle+1
Medium·4 companies·Max freq 100%·Acc 70.2%
ArcesiumMetaAmazon+1
Hard·4 companies·Max freq 100%·Acc 0.6%
Hudson River TradingHudson River TradingGoogle+1
Medium·4 companies·Max freq 100%·Acc 71.3%
QuoraUberAmazon+1
Easy·4 companies·Max freq 100%·Acc 70.1%
Code StudioBloombergAmazon+1
Hard·4 companies·Max freq 100%·Acc 61.5%
TeradataAmazonGoogle+1
Hard·4 companies·Max freq 67%·Acc 42.4%
TuringMicrosoftGoogle+1
Medium·4 companies·Max freq 50%·Acc 31.4%
AmazonBloombergMicrosoft+1
Medium·4 companies·Max freq 42%·Acc 68.4%
IBMAmazonMeta+1
Medium·4 companies·Max freq 29%·Acc 40.2%
GoogleMetaAmazon+1
Medium·4 companies·Max freq 25%·Acc 49.7%
BloombergAmazonGoogle+1
Medium·4 companies·Max freq 15%·Acc 53.6%
GoogleMetaAmazon+1
Medium·4 companies·Max freq 13%·Acc 58.5%
MetaAmazonMicrosoft+1
Medium·4 companies·Max freq 13%·Acc 58.0%
MetaBloombergMicrosoft+1
Medium·3 companies·Max freq 100%·Acc 34.4%
RobinhoodTekionGoogle
Hard·3 companies·Max freq 100%·Acc 39.4%
Deutsche BankPhonePeGoogle
Medium·3 companies·Max freq 97%·Acc 0.3%
Hudson River TradingAmazonGoogle
Medium·3 companies·Max freq 92%·Acc 36.1%
LTIMindtreeGoogleAmazon
Easy·3 companies·Max freq 88%·Acc 51.2%
SquarespaceBloombergAmazon
Medium·3 companies·Max freq 67%·Acc 51.0%
Dream11DE ShawAmazon
Hard·3 companies·Max freq 25%·Acc 53.9%
GoogleAmazonBloomberg
Hard·3 companies·Max freq 25%·Acc 45.7%
GoogleBloombergAmazon
Medium·3 companies·Max freq 16%·Acc 42.9%
GoogleAmazonBloomberg
Hard·2 companies·Max freq 100%·Acc 65.5%
DunzoGoogle
Medium·2 companies·Max freq 88%·Acc 74.9%
BarclaysGoogle
Hard·2 companies·Max freq 75%·Acc 23.4%
RubrikGoogle
Medium·2 companies·Max freq 35%·Acc 0.6%
Capital OneGoogle
Hard·2 companies·Max freq 28%·Acc 35.9%
SalesforceGoogle
Medium·2 companies·Max freq 27%·Acc 26.5%
MicrosoftAmazon
Medium·2 companies·Max freq 27%·Acc 69.7%
MicrosoftAmazon
Medium·2 companies·Max freq 27%·Acc 85.1%
MicrosoftGoogle
Medium·2 companies·Max freq 13%·Acc 84.8%
MetaGoogle
Hard·1 companies·Max freq 100%·Acc 41.6%
Docusign
Medium·1 companies·Max freq 83%·Acc 32.1%
DE Shaw
Medium·1 companies·Max freq 63%·Acc 58.1%
Oracle
Hard·1 companies·Max freq 63%·Acc 23.8%
Oracle
Medium·1 companies·Max freq 25%·Acc 46.1%
Amazon
Medium·1 companies·Max freq 25%·Acc 49.1%
Google
Medium·1 companies·Max freq 25%·Acc 38.2%
Google
# | Problem | Difficulty | Top Companies↓ | Frequency | Acceptance | |
|---|---|---|---|---|---|---|
| #253 | Meeting Rooms II ArrayTwo PointersGreedySortingHeap (Priority Queue)Prefix Sum | Medium | 100% | 52.7% | ||
| #560 | Subarray Sum Equals K ArrayHash TablePrefix Sum | Medium | 88% | 47.7% | ||
| #238 | Product of Array Except Self ArrayPrefix Sum | Medium | 100% | 69.1% | ||
| #528 | Random Pick with Weight ArrayMathBinary SearchPrefix SumRandomized | Medium | 100% | 49.2% | ||
| #410 | Split Array Largest Sum ArrayBinary SearchDynamic ProgrammingGreedyPrefix Sum | Hard | 100% | 60.9% | ||
| #713 | Subarray Product Less Than K ArrayBinary SearchSliding WindowPrefix Sum | Medium | 100% | 54.7% | ||
| #1004 | Max Consecutive Ones III ArrayBinary SearchSliding WindowPrefix Sum | Medium | 88% | 68.0% | ||
| #209 | Minimum Size Subarray Sum ArrayBinary SearchSliding WindowPrefix Sum | Medium | 88% | 52.2% | ||
| #525 | Contiguous Array ArrayHash TablePrefix Sum | Medium | 88% | 51.7% | ||
| #1838 | Frequency of the Most Frequent Element ArrayBinary SearchGreedySliding WindowSortingPrefix Sum | Medium | 100% | 45.0% | ||
| #1094 | Car Pooling ArraySortingHeap (Priority Queue)SimulationPrefix Sum | Medium | 89% | 56.4% | ||
| #1352 | Product of the Last K Numbers ArrayMathDesignData StreamPrefix Sum | Medium | 100% | 63.0% | ||
| #1423 | Maximum Points You Can Obtain from Cards ArraySliding WindowPrefix Sum | Medium | 100% | 58.0% | ||
| #974 | Medium | 70% | 56.5% | |||
| #1413 | Minimum Value to Get Positive Step by Step Sum ArrayPrefix Sum | Easy | 100% | 64.8% | ||
| #304 | Range Sum Query 2D - Immutable ArrayDesignMatrixPrefix Sum | Medium | 71% | 58.6% | ||
| #523 | Continuous Subarray Sum ArrayHash TableMathPrefix SumPigeonhole Principle | Medium | 63% | 31.5% | ||
| #2559 | Count Vowel Strings in Ranges ArrayStringPrefix Sum | Medium | 88% | 67.9% | ||
| #1248 | Count Number of Nice Subarrays ArrayHash TableMathSliding WindowPrefix Sum | Medium | 75% | 75.4% | ||
| #862 | Shortest Subarray with Sum at Least K ArrayBinary SearchQueueSliding WindowHeap (Priority Queue)Prefix SumMonotonic Queue | Hard | 100% | 32.9% | ||
| #303 | Range Sum Query - Immutable ArrayDesignPrefix Sum | Easy | 63% | 72.7% | ||
| #325 | Maximum Size Subarray Sum Equals k ArrayHash TablePrefix Sum | Medium | 63% | 50.9% | ||
| #2021 | Brightest Position on Street ArraySortingPrefix SumOrdered Set | Medium | 100% | 60.7% | ||
| #1664 | Ways to Make a Fair Array ArrayPrefix Sum | Medium | 100% | 67.3% | ||
| #1854 | Maximum Population Year ArrayCountingPrefix Sum | Easy | 100% | 64.3% | ||
| #2406 | Divide Intervals Into Minimum Number of Groups ArrayTwo PointersGreedySortingHeap (Priority Queue)Prefix Sum | Medium | 88% | 63.6% | ||
| #1590 | Make Sum Divisible by P ArrayHash TablePrefix Sum | Medium | 65% | 42.6% | ||
| #1732 | Find the Highest Altitude ArrayPrefix Sum | Easy | 50% | 84.7% | ||
| #930 | Binary Subarrays With Sum ArrayHash TableSliding WindowPrefix Sum | Medium | 41% | 69.3% | ||
| #1524 | Number of Sub-arrays With Odd Sum ArrayMathDynamic ProgrammingPrefix Sum | Medium | 100% | 55.7% | ||
| #2381 | Shifting Letters II ArrayStringPrefix Sum | Medium | 100% | 53.8% | ||
| #3445 | Maximum Difference Between Even and Odd Frequency II StringSliding WindowEnumerationPrefix Sum | Hard | 100% | 48.6% | ||
| #2483 | Minimum Penalty for a Shop StringPrefix Sum | Medium | 100% | 71.2% | ||
| #2145 | Count the Hidden Sequences ArrayPrefix Sum | Medium | 96% | 56.7% | ||
| #2448 | Minimum Cost to Make Array Equal ArrayBinary SearchGreedySortingPrefix Sum | Hard | 75% | 46.8% | ||
| #689 | Maximum Sum of 3 Non-Overlapping Subarrays ArrayDynamic ProgrammingSliding WindowPrefix Sum | Hard | 63% | 59.9% | ||
| #1480 | Running Sum of 1d Array ArrayPrefix Sum | Easy | 50% | 87.0% | ||
| #3191 | Minimum Operations to Make Binary Array Elements Equal to One I ArrayBit ManipulationQueueSliding WindowPrefix Sum | Medium | 50% | 80.4% | ||
| #3494 | Find the Minimum Amount of Time to Brew Potions ArraySimulationPrefix Sum | Medium | 50% | 62.7% | ||
| #1930 | Unique Length-3 Palindromic Subsequences Hash TableStringBit ManipulationPrefix Sum | Medium | 39% | 73.8% | ||
| #1769 | Minimum Number of Operations to Move All Balls to Each Box ArrayStringPrefix Sum | Medium | 38% | 90.2% | ||
| #1371 | Find the Longest Substring Containing Vowels in Even Counts Hash TableStringBit ManipulationPrefix Sum | Medium | 38% | 75.6% | ||
| #1140 | Stone Game II ArrayMathDynamic ProgrammingMinimaxPrefix SumGame TheoryZero-Sum Game | Medium | 25% | 72.8% | ||
| #3714 | Longest Balanced Substring II Hash TableStringPrefix Sum | Medium | 25% | 41.9% | ||
| #1674 | Minimum Moves to Make Array Complementary ArrayHash TablePrefix Sum | Medium | 100% | 64.9% | ||
| #2615 | Sum of Distances ArrayHash TablePrefix Sum | Medium | 100% | 50.3% | ||
| #2439 | Minimize Maximum of Array ArrayBinary SearchDynamic ProgrammingGreedyPrefix Sum | Medium | 100% | 46.6% | ||
| #3152 | Special Array II ArrayBinary SearchPrefix Sum | Medium | 100% | 0.5% | ||
| #3355 | Zero Array Transformation I ArrayPrefix Sum | Medium | 100% | 54.6% | ||
| #3026 | Maximum Good Subarray Sum ArrayHash TablePrefix Sum | Medium | 77% | 22.2% | ||
| #2302 | Count Subarrays With Score Less Than K ArrayBinary SearchSliding WindowPrefix Sum | Hard | 77% | 62.2% | ||
| #2438 | Range Product Queries of Powers ArrayBit ManipulationPrefix Sum | Medium | 68% | 61.2% | ||
| #3432 | Count Partitions with Even Sum Difference ArrayMathPrefix Sum | Easy | 63% | 85.3% | ||
| #3480 | Maximize Subarrays After Removing One Conflicting Pair ArraySegment TreeEnumerationPrefix Sum | Hard | 55% | 64.5% | ||
| #1074 | Number of Submatrices That Sum to Target ArrayHash TableMatrixPrefix Sum | Hard | 55% | 74.6% | ||
| #3652 | Best Time to Buy and Sell Stock using Strategy ArraySliding WindowPrefix Sum | Medium | 50% | 59.7% | ||
| #1109 | Corporate Flight Bookings ArrayPrefix Sum | Medium | 50% | 67.9% | ||
| #307 | Range Sum Query - Mutable ArrayDivide and ConquerDesignBinary Indexed TreeSegment TreeSqrt Decomposition | Medium | 42% | 0.4% | ||
| #3356 | Zero Array Transformation II ArrayTwo PointersBinary SearchPrefix Sum | Medium | 39% | 43.6% | ||
| #3362 | Zero Array Transformation III ArrayTwo PointersGreedySortingHeap (Priority Queue)Prefix Sum | Medium | 28% | 54.7% | ||
| #3737 | Count Subarrays With Majority Element I ArrayHash TableDivide and ConquerSegment TreeMerge SortCountingPrefix Sum | Medium | 25% | 75.7% | ||
| #3333 | Find the Original Typed String II StringDynamic ProgrammingPrefix Sum | Hard | 18% | 45.5% | ||
| #3699 | Number of ZigZag Arrays I Dynamic ProgrammingPrefix Sum | Hard | 18% | 50.5% | ||
| #3354 | Make Array Elements Equal to Zero ArraySimulationPrefix Sum | Easy | 13% | 68.3% | ||
| #1292 | Maximum Side Length of a Square with Sum Less than or Equal to Threshold ArrayBinary SearchMatrixPrefix Sum | Medium | 100% | 65.4% | ||
| #2024 | Maximize the Confusion of an Exam StringBinary SearchSliding WindowPrefix Sum | Medium | 100% | 70.2% | ||
| #3225 | Maximum Score From Grid Operations ArrayDynamic ProgrammingMatrixPrefix Sum | Hard | 100% | 0.6% | ||
| #1878 | Get Biggest Three Rhombus Sums in a Grid ArrayMathSortingHeap (Priority Queue)MatrixPrefix Sum | Medium | 100% | 71.3% | ||
| #1991 | Find the Middle Index in Array ArrayPrefix Sum | Easy | 100% | 70.1% | ||
| #2528 | Maximize the Minimum Powered City ArrayBinary SearchGreedyQueueSliding WindowPrefix Sum | Hard | 100% | 61.5% | ||
| #3636 | Threshold Majority Queries ArrayHash TableBinary SearchDivide and ConquerCountingPrefix Sum | Hard | 78% | 22.4% | ||
| #1703 | Minimum Adjacent Swaps for K Consecutive Ones ArrayGreedySliding WindowPrefix Sum | Hard | 67% | 42.4% | ||
| #1314 | Matrix Block Sum ArrayMatrixPrefix Sum | Medium | 56% | 76.7% | ||
| #3719 | Longest Balanced Subarray I ArrayHash TableDivide and ConquerSegment TreePrefix Sum | Medium | 51% | 65.7% | ||
| #1000 | Minimum Cost to Merge Stones ArrayDynamic ProgrammingPrefix Sum | Hard | 50% | 46.4% | ||
| #3434 | Maximum Frequency After Subarray Operation ArrayHash TableDynamic ProgrammingGreedyEnumerationPrefix Sum | Medium | 50% | 31.4% | ||
| #1856 | Maximum Subarray Min-Product ArrayStackMonotonic StackPrefix SumCartesian Tree | Medium | 50% | 40.6% | ||
| #1685 | Sum of Absolute Differences in a Sorted Array ArrayMathPrefix Sum | Medium | 42% | 68.4% | ||
| #3346 | Maximum Frequency of an Element After Performing Operations I ArrayBinary SearchSliding WindowSortingPrefix Sum | Medium | 29% | 40.2% | ||
| #3381 | Maximum Subarray Sum With Length Divisible by K ArrayHash TablePrefix Sum | Medium | 25% | 49.7% | ||
| #1871 | Jump Game VII StringDynamic ProgrammingSliding WindowPrefix Sum | Medium | 25% | 35.6% | ||
| #2574 | Left and Right Sum Differences ArrayPrefix Sum | Easy | 25% | 89.6% | ||
| #2389 | Longest Subsequence With Limited Sum ArrayBinary SearchGreedySortingPrefix Sum | Easy | 25% | 73.7% | ||
| #2017 | Grid Game ArrayMatrixPrefix Sum | Medium | 25% | 60.9% | ||
| #3129 | Find All Possible Stable Binary Arrays I Dynamic ProgrammingPrefix Sum | Medium | 15% | 53.6% | ||
| #3578 | Count Partitions With Max-Min Difference at Most K ArrayDynamic ProgrammingQueueSliding WindowPrefix SumMonotonic Queue | Medium | 13% | 58.5% | ||
| #2845 | Count of Interesting Subarrays ArrayHash TablePrefix Sum | Medium | 13% | 58.0% | ||
| #2906 | Construct Product Matrix ArrayMatrixPrefix Sum | Medium | 13% | 51.7% | ||
| #3546 | Equal Sum Grid Partition I ArrayMatrixEnumerationPrefix Sum | Medium | 13% | 52.9% | ||
| #1712 | Ways to Split Array Into Three Subarrays ArrayTwo PointersBinary SearchPrefix Sum | Medium | 100% | 34.4% | ||
| #1889 | Minimum Space Wasted From Packaging ArrayBinary SearchSortingPrefix Sum | Hard | 100% | 33.7% | ||
| #2968 | Apply Operations to Maximize Frequency Score ArrayBinary SearchSliding WindowSortingPrefix Sum | Hard | 100% | 39.4% | ||
| #1895 | Largest Magic Square ArrayMatrixPrefix Sum | Medium | 100% | 75.2% | ||
| #1310 | XOR Queries of a Subarray ArrayBit ManipulationPrefix Sum | Medium | 100% | 78.0% | ||
| #2772 | Apply Operations to Make All Array Elements Equal to Zero ArrayPrefix Sum | Medium | 97% | 0.3% | ||
| #2271 | Maximum White Tiles Covered by a Carpet ArrayBinary SearchGreedySliding WindowSortingPrefix Sum | Medium | 92% | 36.1% | ||
| #1893 | Check if All the Integers in a Range Are Covered ArrayHash TablePrefix Sum | Easy | 88% | 51.2% | ||
| #2055 | Plates Between Candles ArrayStringBinary SearchPrefix Sum | Medium | 88% | 47.6% | ||
| #1943 | Describe the Painting ArrayHash TableSortingPrefix Sum | Medium | 88% | 52.7% | ||
| #3028 | Ant on the Boundary ArraySimulationPrefix Sum | Easy | 75% | 74.6% | ||
| #1124 | Longest Well-Performing Interval ArrayHash TableStackMonotonic StackPrefix Sum | Medium | 75% | 37.9% | ||
| #2222 | Number of Ways to Select Buildings StringDynamic ProgrammingPrefix Sum | Medium | 67% | 51.0% | ||
| #2488 | Count Subarrays With Median K ArrayHash TablePrefix Sum | Hard | 52% | 49.0% | ||
| #1588 | Sum of All Odd Length Subarrays ArrayMathPrefix Sum | Easy | 50% | 84.1% | ||
| #2536 | Increment Submatrices by One ArrayMatrixPrefix Sum | Medium | 42% | 73.8% | ||
| #1422 | Maximum Score After Splitting a String StringPrefix Sum | Easy | 30% | 65.1% | ||
| #731 | My Calendar II ArrayBinary SearchDesignSegment TreePrefix SumOrdered Set | Medium | 30% | 63.3% | ||
| #2485 | Find the Pivot Integer MathPrefix Sum | Easy | 25% | 83.8% | ||
| #308 | Range Sum Query 2D - Mutable ArrayDesignBinary Indexed TreeSegment TreeMatrixSqrt Decomposition | Medium | 25% | 45.5% | ||
| #3347 | Maximum Frequency of an Element After Performing Operations II ArrayBinary SearchSliding WindowSortingPrefix Sum | Hard | 25% | 53.9% | ||
| #363 | Max Sum of Rectangle No Larger Than K ArrayBinary SearchMatrixPrefix SumOrdered Set | Hard | 25% | 45.7% | ||
| #848 | Shifting Letters ArrayStringPrefix Sum | Medium | 25% | 46.3% | ||
| #995 | Minimum Number of K Consecutive Bit Flips ArrayBit ManipulationQueueSliding WindowPrefix SumBrute-Force Search | Hard | 16% | 0.6% | ||
| #3756 | Concatenate Non-Zero Digits and Multiply by Sum II MathStringPrefix Sum | Medium | 16% | 42.9% | ||
| #3312 | Sorted GCD Pair Queries ArrayHash TableMathBinary SearchCombinatoricsCountingNumber TheoryPrefix SumEuclidean AlgorithmGreatest Common Divisor | Hard | 16% | 0.6% | ||
| #1420 | Build Array Where You Can Find The Maximum Exactly K Comparisons Dynamic ProgrammingPrefix Sum | Hard | 100% | 65.5% | ||
| #2121 | Intervals Between Identical Elements ArrayHash TablePrefix Sum | Medium | 100% | 48.1% | ||
| #3709 | Design Exam Scores Tracker ArrayBinary SearchDesignPrefix Sum | Medium | 92% | 0.4% | ||
| #2552 | Count Increasing Quadruplets ArrayDynamic ProgrammingBinary Indexed TreeEnumerationPrefix Sum | Hard | 92% | 34.5% | ||
| #2955 | Number of Same-End Substrings ArrayHash TableStringCountingPrefix Sum | Medium | 90% | 61.7% | ||
| #3070 | Count Submatrices with Top-Left Element and Sum Less Than k ArrayMatrixPrefix Sum | Medium | 88% | 74.9% | ||
| #3077 | Maximum Strength of K Disjoint Subarrays ArrayDynamic ProgrammingPrefix Sum | Hard | 75% | 28.1% | ||
| #3410 | Maximize Subarray Sum After Removing All Occurrences of One Element ArrayHash TableDivide and ConquerDynamic ProgrammingSegment TreePrefix Sum | Hard | 75% | 23.4% | ||
| #1589 | Maximum Sum Obtained of Any Permutation ArrayGreedySortingPrefix Sum | Medium | 75% | 41.2% | ||
| #2398 | Maximum Number of Robots Within Budget ArrayBinary SearchQueueSliding WindowHeap (Priority Queue)Prefix SumMonotonic Queue | Hard | 67% | 38.8% | ||
| #3900 | Longest Balanced Substring After One Swap Hash TableStringPrefix Sum | Medium | 64% | 0.1% | ||
| #3653 | XOR After Range Multiplication Queries I ArrayDivide and ConquerSimulationPrefix Sum | Medium | 63% | 73.3% | ||
| #3655 | XOR After Range Multiplication Queries II ArrayDivide and ConquerPrefix Sum | Hard | 63% | 47.7% | ||
| #1829 | Maximum XOR for Each Query ArrayBit ManipulationPrefix Sum | Medium | 50% | 84.7% | ||
| #3413 | Maximum Coins From K Consecutive Bags ArrayBinary SearchGreedySliding WindowSortingPrefix Sum | Medium | 47% | 25.7% | ||
| #3130 | Find All Possible Stable Binary Arrays II Dynamic ProgrammingPrefix Sum | Hard | 42% | 58.8% | ||
| #2237 | Count Positions on Street With Required Brightness ArrayPrefix Sum | Medium | 35% | 0.6% | ||
| #497 | Random Point in Non-overlapping Rectangles ArrayMathBinary SearchReservoir SamplingPrefix SumOrdered SetRandomized | Medium | 28% | 40.1% | ||
| #2025 | Maximum Number of Ways to Partition an Array ArrayHash TableCountingEnumerationPrefix Sum | Hard | 28% | 35.9% | ||
| #3728 | Stable Subarrays With Equal Boundary and Interior Sum ArrayHash TablePrefix Sum | Medium | 27% | 26.5% | ||
| #3212 | Count Submatrices With Equal Frequency of X and Y ArrayMatrixPrefix Sum | Medium | 27% | 69.7% | ||
| #2391 | Minimum Amount of Time to Collect Garbage ArrayStringPrefix Sum | Medium | 27% | 85.1% | ||
| #3862 | Find the Smallest Balanced Index ArrayPrefix Sum | Medium | 25% | 19.5% | ||
| #2256 | Minimum Average Difference ArrayPrefix Sum | Medium | 25% | 44.0% | ||
| #2100 | Find Good Days to Rob the Bank ArrayDynamic ProgrammingPrefix Sum | Medium | 25% | 51.9% | ||
| #1525 | Number of Good Ways to Split a String Hash TableStringDynamic ProgrammingBit ManipulationPrefix Sum | Medium | 25% | 68.5% | ||
| #813 | Largest Sum of Averages ArrayDynamic ProgrammingPrefix Sum | Medium | 25% | 55.2% | ||
| #3721 | Longest Balanced Subarray II ArrayHash TableDivide and ConquerSegment TreePrefix Sum | Hard | 25% | 33.8% | ||
| #370 | Range Addition ArrayPrefix Sum | Medium | 25% | 73.1% | ||
| #1915 | Number of Wonderful Substrings Hash TableStringBit ManipulationPrefix Sum | Medium | 25% | 66.6% | ||
| #1442 | Count Triplets That Can Form Two Arrays of Equal XOR ArrayHash TableMathBit ManipulationPrefix Sum | Medium | 13% | 84.8% | ||
| #3427 | Sum of Variable Length Subarrays ArrayPrefix Sum | Easy | 13% | 85.8% | ||
| #3739 | Count Subarrays With Majority Element II ArrayHash TableDivide and ConquerSegment TreeMerge SortPrefix Sum | Hard | 13% | 64.9% | ||
| #3548 | Equal Sum Grid Partition II ArrayHash TableMatrixEnumerationPrefix Sum | Hard | 13% | 39.4% | ||
| #2428 | Maximum Sum of an Hourglass ArrayMatrixPrefix Sum | Medium | 100% | 76.4% | ||
| #1687 | Delivering Boxes from Storage to Ports ArrayDynamic ProgrammingSegment TreeQueueHeap (Priority Queue)Prefix SumMonotonic Queue | Hard | 100% | 39.9% | ||
| #3883 | Count Non Decreasing Arrays With Given Digit Sums ArrayDynamic ProgrammingPrefix Sum | Hard | 100% | 41.6% | ||
| #1177 | Can Make Palindrome from Substring ArrayHash TableStringBit ManipulationPrefix Sum | Medium | 100% | 41.8% | ||
| #548 | Split Array with Equal Sum ArrayHash TablePrefix Sum | Hard | 100% | 50.1% | ||
| #2505 | Bitwise OR of All Subsequence Sums ArrayMathBit ManipulationBrainteaserPrefix Sum | Medium | 100% | 64.1% | ||
| #2971 | Find Polygon With the Largest Perimeter ArrayGreedySortingPrefix SumPolygons | Medium | 100% | 65.6% | ||
| #2838 | Maximum Coins Heroes Can Collect ArrayTwo PointersBinary SearchSortingPrefix Sum | Medium | 100% | 68.8% | ||
| #1977 | Number of Ways to Separate Numbers StringDynamic ProgrammingPrefix Sum | Hard | 88% | 21.8% | ||
| #3179 | Find the N-th Value After K Seconds ArrayMathSimulationCombinatoricsPrefix Sum | Medium | 88% | 54.1% | ||
| #3628 | Maximum Number of Subsequences After One Inserting StringDynamic ProgrammingGreedyPrefix Sum | Medium | 83% | 32.1% | ||
| #2875 | Minimum Size Subarray in Infinite Array ArrayHash TableSliding WindowPrefix Sum | Medium | 77% | 32.4% | ||
| #2171 | Removing Minimum Number of Magic Beans ArrayGreedySortingEnumerationPrefix Sum | Medium | 75% | 44.8% | ||
| #2234 | Maximum Total Beauty of the Gardens ArrayTwo PointersBinary SearchGreedySortingEnumerationPrefix Sum | Hard | 75% | 30.2% | ||
| #2489 | Number of Substrings With Fixed Ratio Hash TableMathStringPrefix Sum | Medium | 75% | 57.2% | ||
| #1872 | Stone Game VIII ArrayMathDynamic ProgrammingMinimaxPrefix SumGame TheoryZero-Sum Game | Hard | 75% | 54.2% | ||
| #3096 | Minimum Levels to Gain More Points ArrayPrefix Sum | Medium | 65% | 40.5% | ||
| #3251 | Find the Count of Monotonic Pairs II ArrayMathDynamic ProgrammingCombinatoricsPrefix Sum | Hard | 64% | 24.9% | ||
| #3511 | Make a Positive Array ArrayGreedyPrefix Sum | Medium | 63% | 36.4% | ||
| #2132 | Stamping the Grid ArrayGreedyMatrixPrefix Sum | Hard | 63% | 35.6% | ||
| #3015 | Count the Number of Houses at a Certain Distance I Breadth-First SearchGraph TheoryPrefix Sum | Medium | 63% | 58.1% | ||
| #3017 | Count the Number of Houses at a Certain Distance II Graph TheoryPrefix Sum | Hard | 63% | 23.8% | ||
| #2640 | Find the Score of All Prefixes of an Array ArrayPrefix Sum | Medium | 63% | 73.0% | ||
| #3086 | Minimum Moves to Pick K Ones ArrayGreedySliding WindowPrefix Sum | Hard | 63% | 21.8% | ||
| #3540 | Minimum Time to Visit All Houses ArrayPrefix Sum | Medium | 63% | 69.2% | ||
| #3891 | Minimum Increase to Maximize Special Indices ArrayDynamic ProgrammingGreedyPrefix Sum | Medium | 50% | 19.8% | ||
| #2420 | Find All Good Indices ArrayDynamic ProgrammingPrefix Sum | Medium | 50% | 41.1% | ||
| #2848 | Points That Intersect With Cars ArrayHash TablePrefix Sum | Easy | 50% | 73.5% | ||
| #2281 | Sum of Total Strength of Wizards ArrayStackMonotonic StackPrefix Sum | Hard | 40% | 29.6% | ||
| #1983 | Widest Pair of Indices With Equal Range Sum ArrayHash TablePrefix Sum | Medium | 27% | 54.1% | ||
| #2015 | Average Height of Buildings in Each Segment ArraySortingHeap (Priority Queue)Prefix Sum | Medium | 27% | 58.7% | ||
| #2207 | Maximize Number of Subsequences in a String StringGreedyPrefix Sum | Medium | 25% | 36.2% | ||
| #2947 | Count Beautiful Substrings I Hash TableMathStringEnumerationNumber TheoryPrefix Sum | Medium | 25% | 61.5% | ||
| #1621 | Number of Sets of K Non-Overlapping Line Segments MathDynamic ProgrammingCombinatoricsPrefix Sum | Medium | 25% | 46.1% | ||
| #1788 | Maximize the Beauty of the Garden ArrayHash TableGreedyPrefix Sum | Hard | 25% | 65.0% | ||
| #2219 | Maximum Sum Score of Array ArrayPrefix Sum | Medium | 25% | 62.8% | ||
| #2949 | Count Beautiful Substrings II Hash TableMathStringNumber TheoryPrefix Sum | Hard | 25% | 27.8% | ||
| #3864 | Minimum Cost to Partition a Binary String StringDivide and ConquerPrefix Sum | Hard | 25% | 52.6% | ||
| #1444 | Number of Ways of Cutting a Pizza ArrayDynamic ProgrammingMemoizationMatrixPrefix Sum | Hard | 25% | 61.6% | ||
| #732 | My Calendar III Binary SearchDesignSegment TreePrefix SumOrdered Set | Hard | 25% | 72.0% | ||
| #2218 | Maximum Value of K Coins From Piles ArrayDynamic ProgrammingPrefix Sum | Hard | 25% | 60.5% | ||
| #1738 | Find Kth Largest XOR Coordinate Value ArrayDivide and ConquerBit ManipulationSortingHeap (Priority Queue)MatrixPrefix SumQuickselect | Medium | 25% | 64.4% | ||
| #2478 | Number of Beautiful Partitions StringDynamic ProgrammingPrefix Sum | Hard | 25% | 33.2% | ||
| #644 | Maximum Average Subarray II ArrayBinary SearchPrefix Sum | Hard | 25% | 37.8% | ||
| #1546 | Maximum Number of Non-Overlapping Subarrays With Sum Equals Target ArrayHash TableGreedyPrefix Sum | Medium | 25% | 49.1% | ||
| #1737 | Change Minimum Characters to Satisfy One of Three Conditions Hash TableStringCountingPrefix Sum | Medium | 25% | 38.2% | ||
| #1906 | Minimum Absolute Difference Queries ArrayPrefix Sum | Medium | 25% | 45.9% | ||
| #2209 | Minimum White Tiles After Covering With Carpets StringDynamic ProgrammingPrefix Sum | Hard | 25% | 39.1% | ||
| #3698 | Split Array With Minimum Difference ArrayPrefix Sum | Medium | 18% | 33.6% | ||
| #3797 | Count Routes to Climb a Rectangular Grid ArrayDynamic ProgrammingMatrixPrefix Sum | Hard | 13% | 25.1% | ||
| #3969 | Valid Subarrays With Matching Sum Digits I ArrayHash TableSliding WindowEnumerationPrefix Sum | Medium | 13% | 46.7% | ||
| #3486 | Longest Special Path II ArrayHash TableTreeDepth-First SearchPrefix Sum | Hard | 13% | 19.8% | ||
| #798 | Smallest Rotation with Highest Score ArrayPrefix Sum | Hard | 13% | 54.3% | ||
| #3538 | Merge Operations for Minimum Travel Time ArrayDynamic ProgrammingPrefix Sum | Hard | 13% | 31.4% | ||
| #3361 | Shift Distance Between Two Strings ArrayStringPrefix Sum | Medium | 13% | 53.8% | ||
| #3599 | Partition Array to Minimize XOR ArrayDynamic ProgrammingBit ManipulationPrefix Sum | Medium | 13% | 41.6% |
Showing 205 of 205 problems in Prefix Sum & Hash MapFiltered: All Companies