Top K Elements & Priority Queues
Data StructuresTracking extremes, medians, and K largest/smallest elements in dynamic streams
190 problems·13 Easy·107 Medium·70 Hard
Pattern Study Guide & Cheat Sheet▼
Dynamically maintain the K extreme elements using a binary heap, turning an O(N log N) full sort into O(N log K) time.
Core Invariant: The Heap Inversion Principle: To maintain the top K LARGEST elements, use a MIN-heap of size K! The heap root holds the smallest of the top K; if a new element is larger than root, pop root and push new.
Recognize it (Keywords & Signals)
- Find K-th largest or K-th smallest element in array or stream
- Top K frequent elements or most frequent words
- Merge K sorted linked lists / arrays
- Find median from data stream (dual heap: max-heap + min-heap)
- Task scheduler / meeting rooms
When NOT to use
K is very close to N (quickselect or full sort is faster and simpler), or random indexed lookups are needed.
How to solve (Step-by-step)
- 1.To find top K largest: maintain `min_heap = []` (in Python `heapq` is a min-heap by default).
- 2.Iterate through elements or frequency counts.
- 3.Push onto heap: `heapq.heappush(heap, item)`.
- 4.If `len(heap) > k`: pop smallest element: `heapq.heappop(heap)`.
- 5.Heap now holds the K largest elements; root `heap[0]` is the K-th largest.
Watch for (Interview Traps)
- Using a max-heap for top K largest (requires pushing all N elements taking O(N log N) space and time)
- Python's `heapq` is MIN-heap only; negate numbers `(-val)` to emulate max-heap behavior
- Tuple comparison tie-breakers: if frequencies match, Python compares the next tuple element (ensure elements are comparable)
Top K Frequent Elements (Min-Heap of size K)
import heapq
from collections import Counter
def top_k_frequent(nums: list[int], k: int) -> list[int]:
freq_map = Counter(nums)
# Min-heap stores tuples: (frequency, number)
min_heap = []
for num, count in freq_map.items():
heapq.heappush(min_heap, (count, num))
# Keep heap size <= k so root is always the smallest among top k
if len(min_heap) > k:
heapq.heappop(min_heap)
return [num for count, num in min_heap]- Cost
- O(n log k) vs O(n log n) full sort · O(k) auxiliary memory (Significant speedup when k << n (e.g. k=10, n=1,000,000).)
Canonical problems
#215 Kth Largest Element in an Array: Min-heap of size K yields answer at root heap[0]
#347 Top K Frequent Elements: Heap sorted by frequency maintains top K elements
#295 Find Median from Data Stream: Balance max-heap (lower half) and min-heap (upper half)
#23 Merge k Sorted Lists: Min-heap of size K holds head of each list for O(N log K) merge
⌘K
Hard·47 companies·Max freq 100%·Acc 54.7%
TinderCohesityStackAdapt+44
Medium·45 companies·Max freq 100%·Acc 69.1%
CernerPocket GemsAvito+42
Medium·22 companies·Max freq 100%·Acc 42.2%
HTCMakeMyTripStripe+19
Medium·19 companies·Max freq 100%·Acc 65.2%
Squarepoint CapitalUBSDoorDash+16
Medium·17 companies·Max freq 100%·Acc 57.8%
UberMolocoPhonePe+14
Medium·17 companies·Max freq 88%·Acc 0.8%
TargetWissen TechnologySquarepoint Capital+14
Medium·16 companies·Max freq 100%·Acc 39.0%
GopuffVisaPayPal+13
Easy·13 companies·Max freq 93%·Acc 61.3%
TinderAdobeNeetCode 150+10
Hard·13 companies·Max freq 75%·Acc 50.0%
RobloxPinterestMongoDB+10
Hard·11 companies·Max freq 100%·Acc 70.2%
WinZOPhonePeLyft+8
Hard·8 companies·Max freq 100%·Acc 32.9%
DevRevPhonePeGoldman Sachs+5
Medium·8 companies·Max freq 89%·Acc 61.8%
AsanaPalantirOracle+5
Medium·7 companies·Max freq 100%·Acc 51.0%
FlexeraSalesforceAmazon+4
Medium·7 companies·Max freq 88%·Acc 63.6%
AdobeWalmart LabsIBM+4
Hard·7 companies·Max freq 40%·Acc 69.6%
InfosysAmazonUber+4
Medium·6 companies·Max freq 100%·Acc 30.3%
GrouponMathWorksGoldman Sachs+3
Hard·6 companies·Max freq 100%·Acc 45.6%
WishCitadelApple+3
Medium·6 companies·Max freq 100%·Acc 64.1%
McKinseyVisaTikTok+3
Easy·6 companies·Max freq 75%·Acc 57.3%
AccenturetcsMeta+3
Medium·6 companies·Max freq 63%·Acc 65.9%
NvidiaAmazonBloomberg+3
Medium·5 companies·Max freq 100%·Acc 70.8%
Arista NetworksFortinetJPMorgan Chase+2
Easy·5 companies·Max freq 100%·Acc 65.6%
ZScalerIBMSalesforce+2
Medium·5 companies·Max freq 100%·Acc 65.9%
Bill.comExpediaNvidia+2
Medium·5 companies·Max freq 88%·Acc 60.3%
spinnyAmazonMicrosoft+2
Hard·5 companies·Max freq 75%·Acc 52.4%
InfosysMetaAmazon+2
Hard·5 companies·Max freq 60%·Acc 0.5%
NeetCode 150NeetCode 150Google+2
Medium·5 companies·Max freq 39%·Acc 64.5%
VisaBloombergMeta+2
Easy·5 companies·Max freq 38%·Acc 76.1%
GoogleBloombergMeta+2
Easy·5 companies·Max freq 25%·Acc 65.2%
MetaMicrosoftGoogle+2
Medium·4 companies·Max freq 100%·Acc 54.1%
RobinhoodCitadelJane Street+1
Hard·4 companies·Max freq 100%·Acc 54.7%
JioAmerican ExpressAmazon+1
Medium·4 companies·Max freq 100%·Acc 71.3%
QuoraUberAmazon+1
Medium·4 companies·Max freq 100%·Acc 43.8%
MathWorksGSA CapitalBloomberg+1
Medium·4 companies·Max freq 65%·Acc 55.5%
UberGoogleBloomberg+1
Hard·4 companies·Max freq 63%·Acc 56.1%
AtlassianMicrosoftGoogle+1
Medium·4 companies·Max freq 51%·Acc 45.8%
tcsMetaAmazon+1
Hard·3 companies·Max freq 100%·Acc 24.0%
HuaweiWorldQuantDE Shaw
Medium·3 companies·Max freq 65%·Acc 52.4%
PhonePeGoogleAmazon
Medium·3 companies·Max freq 60%·Acc 0.5%
NutanixMicrosoftOracle
Medium·3 companies·Max freq 52%·Acc 67.6%
UberAmazonGoogle
Hard·3 companies·Max freq 50%·Acc 61.6%
LinkedInAmazonGoogle
Hard·3 companies·Max freq 16%·Acc 39.0%
AmazonMicrosoftGoogle
Hard·3 companies·Max freq 13%·Acc 13.6%
MetaAmazonGoogle
Medium·3 companies·Max freq 13%·Acc 58.3%
MetaAmazonGoogle
Medium·2 companies·Max freq 100%·Acc 0.7%
Hudson River TradingHudson River Trading
Hard·2 companies·Max freq 100%·Acc 65.5%
VMwareGoogle
Medium·2 companies·Max freq 93%·Acc 49.6%
SamsungBarclays
Medium·2 companies·Max freq 88%·Acc 0.5%
Booking.comBooking.com
Medium·2 companies·Max freq 77%·Acc 61.0%
FlipkartGoldman Sachs
Hard·2 companies·Max freq 75%·Acc 51.6%
Oscar HealthGoogle
Easy·2 companies·Max freq 50%·Acc 73.9%
AmazonGoogle
Medium·2 companies·Max freq 38%·Acc 31.0%
MicrosoftGoogle
Medium·2 companies·Max freq 27%·Acc 33.5%
AmazonGoogle
Hard·2 companies·Max freq 25%·Acc 62.5%
MetaAmazon
Medium·1 companies·Max freq 100%·Acc 66.2%
Amdocs
Medium·1 companies·Max freq 25%·Acc 63.5%
Amazon
Medium·1 companies·Max freq 25%·Acc 29.4%
Amazon
Medium·1 companies·Max freq 25%·Acc 41.5%
Google
Hard·1 companies·Max freq 13%·Acc 49.9%
Google
# | Problem | Difficulty | Top Companies↓ | Frequency | Acceptance | |
|---|---|---|---|---|---|---|
| #347 | Top K Frequent Elements ArrayHash TableDivide and ConquerSortingHeap (Priority Queue)Bucket SortCountingQuickselect | Medium | 100% | 66.8% | ||
| #23 | Merge k Sorted Lists Linked ListDivide and ConquerHeap (Priority Queue)Merge SortTournament Sort | Hard | 100% | 60.0% | ||
| #239 | Sliding Window Maximum ArrayQueueSliding WindowHeap (Priority Queue)Monotonic QueueRange Minimum/Maximum Query | Hard | 100% | 49.0% | ||
| #295 | Find Median from Data Stream Two PointersDesignSortingHeap (Priority Queue)Data Stream | Hard | 100% | 54.7% | ||
| #253 | Meeting Rooms II ArrayTwo PointersGreedySortingHeap (Priority Queue)Prefix Sum | Medium | 100% | 52.7% | ||
| #215 | Kth Largest Element in an Array ArrayDivide and ConquerSortingHeap (Priority Queue)Quickselect | Medium | 100% | 69.1% | ||
| #621 | Task Scheduler ArrayHash TableGreedySortingHeap (Priority Queue)Counting | Medium | 100% | 63.4% | ||
| #332 | Reconstruct Itinerary ArrayStringDepth-First SearchGraph TheorySortingHeap (Priority Queue)Eulerian CircuitEulerian PathSemi-Eulerian Graph | Hard | 100% | 44.7% | ||
| #692 | Top K Frequent Words ArrayHash TableStringTrieSortingHeap (Priority Queue)Bucket SortCounting | Medium | 100% | 60.4% | ||
| #787 | Cheapest Flights Within K Stops Dynamic ProgrammingDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest Path | Medium | 100% | 42.2% | ||
| #767 | Reorganize String Hash TableStringGreedySortingHeap (Priority Queue)Counting | Medium | 100% | 57.3% | ||
| #658 | Find K Closest Elements ArrayTwo PointersBinary SearchSliding WindowSortingHeap (Priority Queue) | Medium | 88% | 49.9% | ||
| #973 | K Closest Points to Origin ArrayMathDivide and ConquerGeometrySortingHeap (Priority Queue)QuickselectK-D Tree | Medium | 100% | 69.2% | ||
| #1268 | Search Suggestions System ArrayStringBinary SearchTrieSortingHeap (Priority Queue) | Medium | 100% | 65.2% | ||
| #355 | Design Twitter Hash TableLinked ListDesignHeap (Priority Queue) | Medium | 100% | 45.1% | ||
| #1438 | Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit ArrayQueueSliding WindowHeap (Priority Queue)Ordered SetMonotonic Queue | Medium | 100% | 57.8% | ||
| #451 | Sort Characters By Frequency Hash TableStringSortingHeap (Priority Queue)Bucket SortCounting | Medium | 88% | 0.8% | ||
| #1642 | Medium | 100% | 51.0% | |||
| #1353 | Maximum Number of Events That Can Be Attended ArrayGreedySortingHeap (Priority Queue) | Medium | 100% | 39.0% | ||
| #218 | The Skyline Problem ArrayDivide and ConquerBinary Indexed TreeSegment TreeSweep LineSortingHeap (Priority Queue)Ordered Set | Hard | 100% | 45.6% | ||
| #703 | Easy | 93% | 61.3% | |||
| #912 | Sort an Array ArrayDivide and ConquerSortingHeap (Priority Queue)Merge SortBucket SortRadix SortCounting Sort | Medium | 78% | 55.9% | ||
| #642 | Design Search Autocomplete System StringDepth-First SearchDesignTrieSortingHeap (Priority Queue)Data Stream | Hard | 75% | 50.0% | ||
| #378 | Kth Smallest Element in a Sorted Matrix ArrayBinary SearchSortingHeap (Priority Queue)Matrix | Medium | 100% | 64.8% | ||
| #1094 | Car Pooling ArraySortingHeap (Priority Queue)SimulationPrefix Sum | Medium | 89% | 56.4% | ||
| #759 | Employee Free Time ArraySweep LineSortingHeap (Priority Queue) | Hard | 75% | 73.0% | ||
| #480 | Sliding Window Median ArrayHash TableSliding WindowHeap (Priority Queue)Treap | Hard | 67% | 39.0% | ||
| #2402 | Meeting Rooms III ArrayHash TableSortingHeap (Priority Queue)Simulation | Hard | 63% | 51.4% | ||
| #632 | Smallest Range Covering Elements from K Lists ArrayHash TableGreedySliding WindowSortingHeap (Priority Queue) | Hard | 100% | 70.2% | ||
| #743 | Network Delay Time Depth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 100% | 61.0% | ||
| #778 | Swim in Rising Water ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindMinimaxHeap (Priority Queue)MatrixDijkstra's Algorithm | Hard | 78% | 68.0% | ||
| #373 | Find K Pairs with Smallest Sums ArrayHeap (Priority Queue) | Medium | 52% | 42.1% | ||
| #502 | IPO ArrayGreedySortingHeap (Priority Queue) | Hard | 88% | 53.6% | ||
| #1631 | Path With Minimum Effort ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixDijkstra's Algorithm | Medium | 67% | 63.6% | ||
| #264 | Ugly Number II Hash TableMathDynamic ProgrammingHeap (Priority Queue) | Medium | 63% | 49.7% | ||
| #862 | Shortest Subarray with Sum at Least K ArrayBinary SearchQueueSliding WindowHeap (Priority Queue)Prefix SumMonotonic Queue | Hard | 100% | 32.9% | ||
| #1405 | Longest Happy String StringGreedyHeap (Priority Queue) | Medium | 100% | 65.5% | ||
| #3650 | Minimum Cost Path with Edge Reversals Graph TheoryHeap (Priority Queue)Shortest Path | Medium | 89% | 61.8% | ||
| #420 | Strong Password Checker StringGreedyHeap (Priority Queue) | Hard | 88% | 16.0% | ||
| #871 | Minimum Number of Refueling Stops ArrayDynamic ProgrammingGreedyHeap (Priority Queue) | Hard | 79% | 41.6% | ||
| #2812 | Find the Safest Path in a Grid ArrayBinary SearchBreadth-First SearchUnion-FindHeap (Priority Queue)Matrix | Medium | 62% | 57.2% | ||
| #2551 | Put Marbles in Bags ArrayGreedySortingHeap (Priority Queue) | Hard | 50% | 72.1% | ||
| #855 | Exam Room DesignHeap (Priority Queue)Ordered Set | Medium | 100% | 43.6% | ||
| #3170 | Lexicographically Minimum String After Removing Stars Hash TableStringStackGreedyHeap (Priority Queue) | Medium | 100% | 51.0% | ||
| #1696 | Jump Game VI ArrayDynamic ProgrammingQueueHeap (Priority Queue)Monotonic Queue | Medium | 100% | 46.5% | ||
| #2406 | Divide Intervals Into Minimum Number of Groups ArrayTwo PointersGreedySortingHeap (Priority Queue)Prefix Sum | Medium | 88% | 63.6% | ||
| #3607 | Power Grid Maintenance ArrayHash TableDepth-First SearchBreadth-First SearchUnion-FindGraph TheoryHeap (Priority Queue)Ordered Set | Medium | 75% | 56.1% | ||
| #1834 | Single-Threaded CPU ArraySortingHeap (Priority Queue) | Medium | 75% | 47.8% | ||
| #2163 | Minimum Difference in Sums After Removal of Elements ArrayDynamic ProgrammingHeap (Priority Queue) | Hard | 40% | 69.6% | ||
| #1648 | Sell Diminishing-Valued Colored Balls ArrayMathBinary SearchGreedySortingHeap (Priority Queue) | Medium | 100% | 30.3% | ||
| #1606 | Find Servers That Handled Most Number of Requests ArrayHeap (Priority Queue)SimulationOrdered Set | Hard | 100% | 45.6% | ||
| #2034 | Stock Price Fluctuation Hash TableDesignHeap (Priority Queue)Data StreamOrdered Set | Medium | 100% | 49.2% | ||
| #2974 | Minimum Number Game ArraySortingHeap (Priority Queue)Simulation | Easy | 100% | 85.6% | ||
| #1488 | Avoid Flood in The City ArrayHash TableBinary SearchGreedyHeap (Priority Queue) | Medium | 100% | 39.0% | ||
| #630 | Course Schedule III ArrayGreedySortingHeap (Priority Queue) | Hard | 100% | 41.9% | ||
| #2530 | Maximal Score After Applying K Operations ArrayGreedyHeap (Priority Queue) | Medium | 100% | 64.1% | ||
| #2542 | Maximum Subsequence Score ArrayGreedySortingHeap (Priority Queue) | Medium | 75% | 54.8% | ||
| #2099 | Find Subsequence of Length K With the Largest Sum ArrayHash TableSortingHeap (Priority Queue) | Easy | 75% | 57.3% | ||
| #2365 | Task Scheduler II ArrayHash TableSimulation | Medium | 68% | 54.9% | ||
| #2342 | Max Sum of a Pair With Equal Sum of Digits ArrayHash TableSortingHeap (Priority Queue) | Medium | 63% | 65.9% | ||
| #2336 | Smallest Number in Infinite Set Hash TableDesignHeap (Priority Queue)Ordered Set | Medium | 27% | 70.7% | ||
| #2182 | Construct String With Repeat Limit Hash TableStringGreedyHeap (Priority Queue)Counting | Medium | 100% | 70.8% | ||
| #1882 | Process Tasks Using Servers ArrayHeap (Priority Queue) | Medium | 100% | 42.0% | ||
| #1424 | Diagonal Traverse II ArraySortingHeap (Priority Queue) | Medium | 100% | 58.3% | ||
| #2231 | Largest Number After Digit Swaps by Parity SortingHeap (Priority Queue) | Easy | 100% | 65.6% | ||
| #1962 | Remove Stones to Minimize the Total ArrayGreedyHeap (Priority Queue) | Medium | 100% | 65.9% | ||
| #1942 | The Number of the Smallest Unoccupied Chair ArrayHash TableHeap (Priority Queue) | Medium | 88% | 60.3% | ||
| #2940 | Find Building Where Alice and Bob Can Meet ArrayBinary SearchStackBinary Indexed TreeSegment TreeHeap (Priority Queue)Monotonic Stack | Hard | 75% | 52.4% | ||
| #1851 | Minimum Interval to Include Each Query IntervalsArrayBinary SearchSweep LineSortingHeap (Priority Queue) | Hard | 60% | 0.5% | ||
| #505 | The Maze II ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Medium | 54% | 55.2% | ||
| #1514 | Path with Maximum Probability ArrayGraph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 50% | 65.6% | ||
| #2593 | Find Score of an Array After Marking All Elements ArrayHash TableSortingHeap (Priority Queue)Simulation | Medium | 39% | 64.5% | ||
| #1792 | Maximum Average Pass Ratio ArrayGreedyHeap (Priority Queue) | Medium | 38% | 74.1% | ||
| #2762 | Continuous Subarrays ArrayQueueSliding WindowHeap (Priority Queue)Ordered SetMonotonic Queue | Medium | 38% | 58.0% | ||
| #3318 | Find X-Sum of All K-Long Subarrays I ArrayHash TableSliding WindowHeap (Priority Queue) | Easy | 38% | 76.1% | ||
| #3408 | Design Task Manager Hash TableDesignHeap (Priority Queue)Ordered Set | Medium | 30% | 48.9% | ||
| #3362 | Zero Array Transformation III ArrayTwo PointersGreedySortingHeap (Priority Queue)Prefix Sum | Medium | 28% | 54.7% | ||
| #3507 | Minimum Pair Removal to Sort Array I ArrayHash TableLinked ListHeap (Priority Queue)SimulationDoubly-Linked ListOrdered Set | Easy | 25% | 65.2% | ||
| #1337 | The K Weakest Rows in a Matrix ArrayBinary SearchSortingHeap (Priority Queue)Matrix | Easy | 25% | 74.4% | ||
| #1801 | Number of Orders in the Backlog ArrayHeap (Priority Queue)Simulation | Medium | 100% | 54.1% | ||
| #3013 | Divide an Array Into Subarrays With Minimum Cost II ArrayHash TableSliding WindowHeap (Priority Queue) | Hard | 100% | 54.7% | ||
| #1845 | Seat Reservation Manager DesignHeap (Priority Queue) | Medium | 100% | 67.3% | ||
| #1878 | Get Biggest Three Rhombus Sums in a Grid ArrayMathSortingHeap (Priority Queue)MatrixPrefix Sum | Medium | 100% | 71.3% | ||
| #2462 | Total Cost to Hire K Workers ArrayTwo PointersHeap (Priority Queue)Simulation | Medium | 100% | 43.8% | ||
| #2558 | Take Gifts From the Richest Pile ArrayHeap (Priority Queue)Simulation | Easy | 75% | 75.5% | ||
| #3341 | Find Minimum Time to Reach Last Room I ArrayGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 65% | 55.5% | ||
| #2577 | Minimum Time to Visit a Cell In a Grid ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path | Hard | 63% | 56.1% | ||
| #358 | Rearrange String k Distance Apart Hash TableStringGreedySortingHeap (Priority Queue)Counting | Hard | 63% | 40.0% | ||
| #3066 | Minimum Operations to Exceed Threshold Value II ArrayHeap (Priority Queue)Simulation | Medium | 51% | 45.8% | ||
| #2386 | Find the K-Sum of an Array ArraySortingHeap (Priority Queue) | Hard | 50% | 41.7% | ||
| #2353 | Design a Food Rating System ArrayHash TableStringDesignHeap (Priority Queue)Ordered Set | Medium | 38% | 52.9% | ||
| #506 | Relative Ranks ArraySortingHeap (Priority Queue) | Easy | 25% | 74.9% | ||
| #2617 | Minimum Number of Visited Cells in a Grid ArrayDynamic ProgrammingStackBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixMonotonic Stack | Hard | 100% | 24.0% | ||
| #2497 | Maximum Star Sum of a Graph ArrayGreedyGraph TheorySortingHeap (Priority Queue) | Medium | 88% | 42.5% | ||
| #1102 | Path With Maximum Minimum Value ArrayBinary SearchDepth-First SearchBreadth-First SearchUnion-FindHeap (Priority Queue)MatrixDijkstra's Algorithm | Medium | 68% | 54.7% | ||
| #659 | Split Array into Consecutive Subsequences ArrayHash TableGreedyHeap (Priority Queue) | Medium | 65% | 52.4% | ||
| #272 | Closest Binary Search Tree Value II Two PointersStackTreeDepth-First SearchBinary Search TreeHeap (Priority Queue)Binary Tree | Hard | 63% | 61.2% | ||
| #2208 | Minimum Operations to Halve Array Sum ArrayGreedyHeap (Priority Queue) | Medium | 60% | 0.5% | ||
| #3342 | Find Minimum Time to Reach Last Room II ArrayGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 52% | 67.6% | ||
| #2344 | Minimum Deletions to Make Array Divisible ArrayMathSortingHeap (Priority Queue)Number TheoryEuclidean AlgorithmGreatest Common Divisor | Hard | 50% | 61.6% | ||
| #1057 | Campus Bikes ArraySortingHeap (Priority Queue) | Medium | 50% | 59.1% | ||
| #2333 | Minimum Sum of Squared Difference ArrayBinary SearchGreedySortingHeap (Priority Queue) | Medium | 50% | 26.9% | ||
| #857 | Minimum Cost to Hire K Workers ArrayGreedySortingHeap (Priority Queue) | Hard | 25% | 63.7% | ||
| #1776 | Car Fleet II ArrayMathStackHeap (Priority Queue)Monotonic Stack | Hard | 25% | 58.2% | ||
| #3510 | Minimum Pair Removal to Sort Array II ArrayHash TableLinked ListHeap (Priority Queue)SimulationDoubly-Linked ListOrdered Set | Hard | 16% | 39.0% | ||
| #3286 | Find a Safe Walk Through a Grid ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path | Medium | 15% | 55.3% | ||
| #3266 | Final Array State After K Multiplication Operations II ArrayHeap (Priority Queue)Simulation | Hard | 13% | 13.6% | ||
| #3296 | Minimum Number of Seconds to Make Mountain Height Zero ArrayMathBinary SearchGreedyHeap (Priority Queue) | Medium | 13% | 58.3% | ||
| #3691 | Maximum Total Subarray Value II ArrayGreedySegment TreeHeap (Priority Queue) | Hard | 13% | 41.7% | ||
| #2285 | Maximum Total Importance of Roads GreedyGraph TheorySortingHeap (Priority Queue) | Medium | 100% | 0.7% | ||
| #2512 | Reward Top K Students ArrayHash TableStringSortingHeap (Priority Queue) | Medium | 100% | 0.5% | ||
| #1675 | Minimize Deviation in Array ArrayGreedyHeap (Priority Queue)Ordered Set | Hard | 100% | 54.0% | ||
| #2263 | Make Array Non-decreasing or Non-increasing ArrayDynamic ProgrammingGreedyHeap (Priority Queue) | Hard | 100% | 65.5% | ||
| #3123 | Find Edges in Shortest Paths Depth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)Shortest Path | Hard | 100% | 46.9% | ||
| #2931 | Maximum Spending After Buying Items ArrayGreedySortingHeap (Priority Queue)Matrix | Hard | 100% | 61.4% | ||
| #1425 | Constrained Subsequence Sum ArrayDynamic ProgrammingQueueSliding WindowHeap (Priority Queue)Monotonic Queue | Hard | 100% | 56.5% | ||
| #3080 | Mark Elements on Array by Performing Queries ArrayHash TableSortingHeap (Priority Queue)Simulation | Medium | 93% | 49.6% | ||
| #3049 | Earliest Second to Mark Indices II ArrayBinary SearchGreedyHeap (Priority Queue) | Hard | 88% | 22.7% | ||
| #2146 | K Highest Ranked Items Within a Price Range ArrayBreadth-First SearchSortingHeap (Priority Queue)Matrix | Medium | 88% | 0.5% | ||
| #2642 | Design Graph With Shortest Path Calculator Graph TheoryDesignHeap (Priority Queue)Shortest Path | Hard | 88% | 65.4% | ||
| #1912 | Design Movie Rental System ArrayHash TableDesignHeap (Priority Queue)Ordered Set | Hard | 88% | 62.2% | ||
| #2093 | Minimum Cost to Reach City With Discounts Graph TheoryHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 77% | 61.0% | ||
| #1086 | High Five ArrayHash TableSortingHeap (Priority Queue) | Easy | 76% | 74.2% | ||
| #2343 | Query Kth Smallest Trimmed Number ArrayStringDivide and ConquerSortingHeap (Priority Queue)Radix SortQuickselect | Medium | 75% | 47.9% | ||
| #2233 | Maximum Product After K Increments ArrayGreedyHeap (Priority Queue) | Medium | 75% | 44.1% | ||
| #1724 | Checking Existence of Edge Length Limited Paths II Depth-First SearchUnion-FindGraph TheoryDesignSortingHeap (Priority Queue)Minimum Spanning Tree | Hard | 75% | 51.6% | ||
| #2398 | Maximum Number of Robots Within Budget ArrayBinary SearchQueueSliding WindowHeap (Priority Queue)Prefix SumMonotonic Queue | Hard | 67% | 38.8% | ||
| #2456 | Most Popular Video Creator ArrayHash TableStringSortingHeap (Priority Queue) | Medium | 63% | 45.5% | ||
| #675 | Cut Off Trees for Golf Event ArrayBreadth-First SearchHeap (Priority Queue)Matrix | Hard | 63% | 36.6% | ||
| #2611 | Mice and Cheese ArrayGreedySortingHeap (Priority Queue) | Medium | 51% | 48.9% | ||
| #2357 | Make Array Zero by Subtracting Equal Amounts ArrayHash TableGreedySortingHeap (Priority Queue)Simulation | Easy | 50% | 73.9% | ||
| #3092 | Most Frequent IDs ArrayHash TableHeap (Priority Queue)Ordered Set | Medium | 50% | 43.2% | ||
| #3377 | Digit Operations to Make Two Integers Equal MathGraph TheoryHeap (Priority Queue)Number TheoryShortest Path | Medium | 38% | 31.0% | ||
| #3462 | Maximum Sum With at Most K Elements ArrayGreedySortingHeap (Priority Queue)Matrix | Medium | 29% | 60.9% | ||
| #1810 | Minimum Path Cost in a Hidden Grid ArrayDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixInteractiveShortest Path | Medium | 27% | 59.0% | ||
| #3645 | Maximum Total from Optimal Activation Order ArrayTwo PointersGreedySortingHeap (Priority Queue) | Medium | 27% | 33.5% | ||
| #1168 | Optimize Water Distribution in a Village Union-FindGraph TheoryHeap (Priority Queue)Minimum Spanning TreePrim's AlgorithmKruskal's AlgorithmBorůvka's Algorithm | Hard | 25% | 65.6% | ||
| #1439 | Find the Kth Smallest Sum of a Matrix With Sorted Rows ArrayBinary SearchHeap (Priority Queue)Matrix | Hard | 25% | 62.5% | ||
| #1054 | Distant Barcodes ArrayHash TableGreedySortingHeap (Priority Queue)Counting | Medium | 25% | 49.2% | ||
| #2290 | Minimum Obstacle Removal to Reach Corner ArrayBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest Path0-1 BFSDijkstra's Algorithm | Hard | 25% | 70.9% | ||
| #1985 | Find the Kth Largest Integer in the Array ArrayStringDivide and ConquerSortingHeap (Priority Queue)Quickselect | Medium | 13% | 0.5% | ||
| #3620 | Network Recovery Pathways ArrayBinary SearchDynamic ProgrammingGraph TheoryTopological SortHeap (Priority Queue)Shortest Path | Hard | 13% | 50.9% | ||
| #1172 | Dinner Plate Stacks Hash TableStackDesignHeap (Priority Queue) | Hard | 13% | 33.7% | ||
| #2500 | Delete Greatest Value in Each Row ArraySortingHeap (Priority Queue)MatrixSimulation | Easy | 13% | 80.0% | ||
| #3321 | Find X-Sum of All K-Long Subarrays II ArrayHash TableSliding WindowHeap (Priority Queue) | Hard | 13% | 41.2% | ||
| #1687 | Delivering Boxes from Storage to Ports ArrayDynamic ProgrammingSegment TreeQueueHeap (Priority Queue)Prefix SumMonotonic Queue | Hard | 100% | 39.9% | ||
| #1354 | Construct Target Array With Multiple Sums ArrayHeap (Priority Queue) | Hard | 100% | 37.1% | ||
| #3711 | Maximum Transactions Without Negative Balance ArrayGreedyHeap (Priority Queue) | Medium | 100% | 46.1% | ||
| #2662 | Minimum Cost of a Path With Special Roads ArrayGraph TheoryHeap (Priority Queue)Shortest Path | Medium | 100% | 43.5% | ||
| #3391 | Design a 3D Binary Matrix with Efficient Layer Tracking ArrayHash TableDesignHeap (Priority Queue)MatrixOrdered Set | Medium | 100% | 66.2% | ||
| #1500 | Design a File Sharing System Hash TableDesignSortingHeap (Priority Queue)Data Stream | Medium | 100% | 41.7% | ||
| #1338 | Reduce Array Size to The Half ArrayHash TableGreedySortingHeap (Priority Queue) | Medium | 100% | 69.4% | ||
| #1183 | Maximum Number of Ones MathGreedySortingHeap (Priority Queue) | Hard | 100% | 70.7% | ||
| #2532 | Time to Cross a Bridge ArrayHeap (Priority Queue)Simulation | Hard | 50% | 44.4% | ||
| #1705 | Maximum Number of Eaten Apples ArrayGreedyHeap (Priority Queue) | Medium | 50% | 43.7% | ||
| #3885 | Design Event Manager ArrayHash TableDesignHeap (Priority Queue)Ordered Set | Medium | 44% | 50.9% | ||
| #1825 | Finding MK Average DesignQueueHeap (Priority Queue)Data StreamOrdered SetTreap | Hard | 40% | 38.8% | ||
| #2203 | Minimum Weighted Subgraph With the Required Paths Graph TheoryHeap (Priority Queue)Shortest Path | Hard | 38% | 42.7% | ||
| #2349 | Design a Number Container System Hash TableDesignHeap (Priority Queue)Ordered Set | Medium | 38% | 57.1% | ||
| #2015 | Average Height of Buildings in Each Segment ArraySortingHeap (Priority Queue)Prefix Sum | Medium | 27% | 58.7% | ||
| #2599 | Make the Prefix Sum Non-negative ArrayGreedyHeap (Priority Queue) | Medium | 27% | 51.9% | ||
| #3369 | Design an Array Statistics Tracker Hash TableBinary SearchDesignQueueHeap (Priority Queue)Data StreamOrdered Set | Hard | 25% | 35.7% | ||
| #3572 | Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values ArrayHash TableGreedySortingHeap (Priority Queue) | Medium | 25% | 63.5% | ||
| #2973 | Find Number of Coins to Place in Tree Nodes Dynamic ProgrammingTreeDepth-First SearchSortingHeap (Priority Queue)DP on Trees | Hard | 25% | 37.7% | ||
| #3081 | Replace Question Marks in String to Minimize Its Value Hash TableStringGreedySortingHeap (Priority Queue)Counting | Medium | 25% | 29.4% | ||
| #1135 | Connecting Cities With Minimum Cost Union-FindGraph TheoryHeap (Priority Queue)Minimum Spanning Tree | Medium | 25% | 63.6% | ||
| #2102 | Sequentially Ordinal Rank Tracker DesignHeap (Priority Queue)Data StreamOrdered Set | Hard | 25% | 61.5% | ||
| #3767 | Maximize Points After Choosing K Tasks ArrayGreedySortingHeap (Priority Queue) | Medium | 25% | 60.3% | ||
| #3781 | Maximum Score After Binary Swaps ArrayStringGreedyHeap (Priority Queue) | Medium | 25% | 35.4% | ||
| #2714 | Find Shortest Path with K Hops Graph TheoryHeap (Priority Queue)Shortest Path | Hard | 25% | 68.7% | ||
| #1786 | Number of Restricted Paths From First to Last Node Dynamic ProgrammingGraph TheoryTopological SortHeap (Priority Queue)Shortest PathDijkstra's Algorithm | Medium | 25% | 41.5% | ||
| #1388 | Pizza With 3n Slices ArrayDynamic ProgrammingGreedyHeap (Priority Queue) | Hard | 25% | 54.1% | ||
| #1499 | Max Value of Equation ArrayQueueSliding WindowHeap (Priority Queue)Monotonic Queue | Hard | 25% | 45.1% | ||
| #2424 | Longest Uploaded Prefix Hash TableBinary SearchUnion-FindDesignBinary Indexed TreeSegment TreeHeap (Priority Queue)Ordered Set | Medium | 25% | 55.2% | ||
| #683 | K Empty Slots ArrayBinary Indexed TreeSegment TreeQueueSliding WindowHeap (Priority Queue)Ordered SetMonotonic Queue | Hard | 25% | 38.0% | ||
| #1738 | Find Kth Largest XOR Coordinate Value ArrayDivide and ConquerBit ManipulationSortingHeap (Priority Queue)MatrixPrefix SumQuickselect | Medium | 25% | 64.4% | ||
| #1199 | Minimum Time to Build Blocks ArrayMathGreedyHeap (Priority Queue) | Hard | 25% | 46.6% | ||
| #1753 | Maximum Score From Removing Stones MathGreedyHeap (Priority Queue) | Medium | 25% | 68.7% | ||
| #2254 | Design Video Sharing Platform Hash TableDesignHeap (Priority Queue) | Hard | 25% | 64.2% | ||
| #3935 | Power Update After K-th Largest Insertion I ArrayHash TableMathSegment TreeSortingHeap (Priority Queue) | Medium | 16% | 68.0% | ||
| #2454 | Next Greater Element IV ArrayBinary SearchStackSortingHeap (Priority Queue)Monotonic Stack | Hard | 13% | 42.3% | ||
| #3780 | Maximum Sum of Three Numbers Divisible by Three ArrayGreedySortingHeap (Priority Queue) | Medium | 13% | 47.6% | ||
| #3928 | Minimum Cost to Buy Apples II ArrayGraph TheoryHeap (Priority Queue)Shortest Path | Hard | 13% | 31.8% | ||
| #3478 | Choose K Elements With Maximum Sum ArraySortingHeap (Priority Queue) | Medium | 13% | 34.1% | ||
| #1263 | Minimum Moves to Move a Box to Their Target Location ArrayBreadth-First SearchHeap (Priority Queue)Matrix | Hard | 13% | 49.9% | ||
| #2699 | Modify Graph Edge Weights Graph TheoryHeap (Priority Queue)Shortest Path | Hard | 13% | 55.6% | ||
| #3815 | Design Auction System Hash TableDesignHeap (Priority Queue)Ordered Set | Medium | 13% | 41.9% | ||
| #3275 | K-th Nearest Obstacle Queries ArrayHeap (Priority Queue) | Medium | 13% | 49.2% | ||
| #2335 | Minimum Amount of Time to Fill Cups ArrayGreedySortingHeap (Priority Queue) | Easy | 13% | 60.5% | ||
| #499 | The Maze III ArrayStringDepth-First SearchBreadth-First SearchGraph TheoryHeap (Priority Queue)MatrixShortest PathDijkstra's AlgorithmHeuristic SearchA* Search | Hard | 13% | 52.5% |
Showing 190 of 190 problems in Top K Elements & Priority QueuesFiltered: All Companies