DSA question set · 165 questions
Heap / Priority Queue DSA Practice Questions
Explore 165 DSA questions in Heap / Priority Queue. Practice with DSAWiser’s code editor and visualizer.
heap indexingcomplete binary treeheap ordervalidationheap extremaarray traversalsift-upparent comparisonssift-downdeterministic repairtask prioritycomparatorsradix heap helperXORbit lengthnested scankey inequalitybottom-up heap constructiontop-k selectionbounded heapgreedy heap simulationbinary heappriority queuestateful priority queuestateful operationsempty queuebottom-up heapifylinear constructioncomparison countingtop-two scanarithmeticsortingrankingdistinct positive countscountingscheduling formularow sortingcolumn maximafrequency countingfrequency feasibility boundgreedy loadinglinear scanManhattan distancestatic mapcomparatorthreshold countingbounded ordered setbit maskevent replaynode identitylogical deletionsorted frontiersk-way mergingschedulingsorted eventsheaptwo heapsstreaming mediangreedy exchangeprefix sumssliding heaplazy invalidationheapsortin-place sortingheap boundarycooldown schedulingcharacter countsgraph frontierDijkstraexpanded statesfrequency countsgreedy deletionoptional heapmeldable leftist heapskew heaprecursive meldbinomial forestdegree carriesFibonacci heap helpercascading cutspairing heaptwo-pass meldindexed heapstable handlesbidirectional repairstable priority queuemutable prioritiesmulti-source BFSvisited bitmaskminimum spanning treeDSUedge classificationBFSresource statessorted restrictionsbidirectional propagationordered grid targetsbitmask DPminimum set coverpersistent heapstructural sharingmeldFibonacci heapconsolidationdecrease-keyamortized analysis
What’s in this set
The Heap / Priority Queue collection contains 165 problems: 34 basic, 49 easy, 54 medium, 26 hard, 2 very hard. Choose a question at your current level, or follow the collection’s order below.
Topics in this collection include heap indexing, complete binary tree, heap order, validation, heap extrema. Each question shows its own topics and difficulty so you can decide where to begin.
Practice with the code visualizer
- Open a question in the editor and read the statement, inputs, and expected output. Predict the result for a small example before writing code.
- Write a solution and run the examples. If a result differs from your prediction, reduce the input until you can follow each step.
- Step through your code in the visualizer. Use a breakpoint to inspect the state at a specific line, then compare it with your reasoning.
Questions in this set
165 totalOpen a question in the editor to read its statement and examples. Sign in to practice.
- Parent Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Left Child Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Right Child Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Parent and Children Indices in a 1-Indexed Binary Heapheap indexing · complete binary treeBasic
- Is Valid Heap Node Index and Boundary Checkheap indexing · complete binary treeBasic
- Check if a Node is a Leaf in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Last Non-Leaf Node Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Sibling Node Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Binary Heap Height from Element Countheap indexing · complete binary treeBasic
- Count of Leaf Nodes in a Binary Heapheap indexing · complete binary treeBasic
- Node Level in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Maximum Nodes at a Given Heap Levelheap indexing · complete binary treeBasic
- Minimum Elements for a Given Binary Heap Heightheap indexing · complete binary treeBasic
- Maximum Elements for a Given Binary Heap Heightheap indexing · complete binary treeBasic
- First Leaf Node Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
- Verify Min-Heap Property at a Single Nodeheap order · validationBasic
- Verify Max-Heap Property at a Single Nodeheap order · validationBasic
- Validate Entire Array as Min-Heapheap order · validationBasic
- Validate Entire Array as Max-Heapheap order · validationBasic
- First Violation Index of Min-Heap Propertyheap order · validationBasic
- First Violation Index of Max-Heap Propertyheap order · validationBasic
- Peek Minimum Element in a Min-Heapheap extrema · array traversalBasic
- Peek Maximum Element in a Max-Heapheap extrema · array traversalBasic
- Find Maximum Element in a Min-Heapheap extrema · array traversalBasic
- Find Minimum Element in a Max-Heapheap extrema · array traversalBasic
- Single Sift-Up Step in a 0-Indexed Min-Heapsift-up · parent comparisonsBasic
- Single Sift-Up Step in a 0-Indexed Max-Heapsift-up · parent comparisonsBasic
- Smallest Child Index in a 0-Indexed Min-Heapsift-down · deterministic repairBasic
- Largest Child Index in a 0-Indexed Max-Heapsift-down · deterministic repairBasic
- Single Sift-Down Step in a 0-Indexed Min-Heapsift-down · deterministic repairBasic
- Single Sift-Down Step in a 0-Indexed Max-Heapsift-down · deterministic repairBasic
- Priority Queue Peek Highest Priority Tasktask priority · comparatorsBasic
- Compute a Radix-Heap Bucket Indexradix heap helper · XOR · bit lengthBasic
- Check That Corrupted Item Keys Never Decreasenested scan · key inequalityBasic
- Full Sift-Up in a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
- Full Sift-Up in a 0-Indexed Max-Heapsift-up · parent comparisonsEasy
- Count Swaps During Sift-Up in a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
- Full Sift-Down from Root in a 0-Indexed Min-Heapsift-down · deterministic repairEasy
- Full Sift-Down from Root in a 0-Indexed Max-Heapsift-down · deterministic repairEasy
- Insert Element into a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
- Insert Element into a 0-Indexed Max-Heapsift-up · parent comparisonsEasy
- Extract Minimum Element from a 0-Indexed Min-Heapsift-down · deterministic repairEasy
- Extract Maximum Element from a 0-Indexed Max-Heapsift-down · deterministic repairEasy
- Replace Root in a 0-Indexed Min-Heapsift-down · deterministic repairEasy
- Replace Root in a 0-Indexed Max-Heapsift-down · deterministic repairEasy
- Decrease Key in a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
- Increase Key in a 0-Indexed Max-Heapsift-up · parent comparisonsEasy
- Delete Element at Arbitrary Index in a 0-Indexed Min-Heapsift-down · deterministic repairEasy
- Build Min-Heap from Unsorted Arraybottom-up heap constructionEasy
- Build Max-Heap from Unsorted Arraybottom-up heap constructionEasy
- Convert Min-Heap Array to Max-Heap Arraybottom-up heap constructionEasy
- Priority Queue Enqueue Task with Prioritytask priority · comparatorsEasy
- Kth Largest Element in a Streamtop-k selection · bounded heapEasy
- Last Stone Weightgreedy heap simulationEasy
- The K Weakest Rows in a Matrixbinary heap · priority queueEasy
- Take Gifts From the Richest Pilegreedy heap simulationEasy
- Seat Reservation Manager Simulationstateful priority queueEasy
- Maximize Sum of Array After K Negationsgreedy heap simulationEasy
- Find Subsequence of Length K With the Largest Sumtop-k selection · bounded heapEasy
- Sum of Elements Between K1-th and K2-th Smallest Elementsbinary heap · priority queueEasy
- Merge Two Binary Max-Heapsbottom-up heap constructionEasy
- Smallest Number in Infinite Set Simulationstateful priority queueEasy
- Kth Distinct Largest Integertop-k selection · bounded heapEasy
- Top K Sum of Speedstop-k selection · bounded heapEasy
- Minimum Sum of Squares After K Decrementsgreedy heap simulationEasy
- Maximal Score After Applying K Operationsgreedy heap simulationEasy
- Least Quality Sum for K Chosen Workerstop-k selection · bounded heapEasy
- Minimum Operations to Exceed Threshold Value IIgreedy heap simulationEasy
- Implement Mixed Min-Heap Operationsbinary heap · stateful operations · empty queueEasy
- Count Comparisons in Bottom-Up Heap Constructionbottom-up heapify · linear construction · comparison countingEasy
- Maximum Product of Two Elements in an Arraytop-two scan · arithmeticEasy
- Relative Rankssorting · rankingEasy
- Make Array Zero by Subtracting Equal Amountsdistinct positive countsEasy
- Minimum Amount of Time to Fill Cupscounting · scheduling formulaEasy
- Delete Greatest Value in Each Rowrow sorting · column maximaEasy
- Sort Array by Increasing Frequencyfrequency counting · sortingEasy
- Check if Characters Can Be Reorganized Without Adjacent Duplicatesfrequency feasibility boundEasy
- Maximum Units on a Trucksorting · greedy loadingEasy
- Nearest Valid Point with Smallest Indexlinear scan · Manhattan distanceEasy
- Highest-Rated Food by Cuisinestatic map · comparatorEasy
- Minimum Operations to Exceed Threshold Value Ithreshold countingEasy
- Ordered-Set Predecessor and Successor in a Small Universebounded ordered set · bit maskEasy
- Logical Deletion Event Snapshot Replayevent replay · node identity · logical deletionEasy
- Sort an Almost Sorted Arraysorted frontiers · k-way mergingMedium
- Minimum Cost to Connect Sticksgreedy heap simulationMedium
- Kth Largest Element in an Arraytop-k selection · bounded heapMedium
- Kth Smallest Element in an Arraytop-k selection · bounded heapMedium
- K Closest Points to Origintop-k selection · bounded heapMedium
- Top K Frequent Elementstop-k selection · bounded heapMedium
- Minimum Operations to Halve Array Sumgreedy heap simulationMedium
- Find K Pairs with Smallest Sumssorted frontiers · k-way mergingMedium
- Reduce Array Size to The Halfgreedy heap simulationMedium
- Top K Frequent Wordstop-k selection · bounded heapMedium
- Kth Smallest Pair Sum Across Two Sorted Arrayssorted frontiers · k-way mergingMedium
- Car Pooling Capacity Checkscheduling · sorted events · heapMedium
- Minimum Number of Meeting Roomsscheduling · sorted events · heapMedium
- Maximum Product After K Incrementsgreedy heap simulationMedium
- Kth Smallest Prime Fractionsorted frontiers · k-way mergingMedium
- Process Tasks Using Serversscheduling · sorted events · heapMedium
- Running Median of an Integer Streamtwo heaps · streaming medianMedium
- Maximum Subsequence Scoregreedy exchange · heap · sortingMedium
- Kth Smallest Element in a Sorted Matrixsorted frontiers · k-way mergingMedium
- Maximum Subarray Sum with Bounded Lengthprefix sums · sliding heap · lazy invalidationMedium
- In-Place Heapsort in Ascending Orderheapsort · in-place sorting · heap boundaryMedium
- Merge K Sorted Arrayssorted frontiers · k-way mergingMedium
- Task Scheduler with Cooldown Intervalscheduling · sorted events · heapMedium
- Reorganize String Distance K Feasibilitycooldown scheduling · character countsMedium
- K Pairs with Smallest Productssorted frontiers · k-way mergingMedium
- Single Source Shortest Path via Dijkstragraph frontier · Dijkstra · expanded statesMedium
- Network Delay Timegraph frontier · Dijkstra · expanded statesMedium
- Path with Minimum Effortgraph frontier · Dijkstra · expanded statesMedium
- Swim in Rising Watergraph frontier · Dijkstra · expanded statesMedium
- Single-Threaded CPU Task Processing Orderscheduling · sorted events · heapMedium
- Maximum CPU Load During Overlapping Jobsscheduling · sorted events · heapMedium
- Frontier Kth Smallest Element in a Multiplication Tablesorted frontiers · k-way mergingMedium
- Maximum Average Pass Ratiogreedy heap simulationMedium
- Cheapest Flights Within K Stopsgraph frontier · Dijkstra · expanded statesMedium
- Longest Happy String Maximum Lengthgreedy heap simulationMedium
- Furthest Building You Can Reachgreedy heap simulationMedium
- Divide Intervals Into Minimum Number of Groupsscheduling · sorted events · heapMedium
- Maximum Number of Events That Can Be Attendedgreedy heap simulationMedium
- Stock Price Fluctuation Systemstateful priority queueMedium
- Minimum Deletions to Make Character Frequencies Uniquefrequency counts · greedy deletion · optional heapMedium
- Recent Tweets Feed Extractionstateful priority queueMedium
- Rearrange String with a Cooldown Priority Queuecooldown scheduling · character countsMedium
- Maximum Frequency Stackstateful priority queueMedium
- Sliding Window Maximum via Lazy Heap Invalidationprefix sums · sliding heap · lazy invalidationMedium
- Minimum Cost to Reach Destination with Toll Discountsgraph frontier · Dijkstra · expanded statesMedium
- Minimum-Effort Path Through a 3D Gridgraph frontier · Dijkstra · expanded statesMedium
- Maximum Subarray Sum with Length Bounded Between K1 and K2prefix sums · sliding heap · lazy invalidationMedium
- Meldable Leftist Min-Heap Operationsmeldable leftist heapMedium
- Skew Heap Meld Preorder Reconstructionskew heap · recursive meldMedium
- Binomial Heap Forest Unionbinomial forest · degree carriesMedium
- Fibonacci Heap Cascading Cut SimulationFibonacci heap helper · cascading cutsMedium
- Pairing Heap Two-Pass Meld Preorderpairing heap · two-pass meldMedium
- Indexed Min-Priority Queue with Change-Key and Deletionindexed heap · stable handles · bidirectional repairMedium
- Stable Task Priorities with Updates and Cancellationstable priority queue · lazy invalidation · mutable prioritiesMedium
- Split Array into Consecutive Subsequences Validationgreedy exchange · heap · sortingHard
- Minimum Number of Refueling Stopsgreedy exchange · heap · sortingHard
- Sliding Window Mediantwo heaps · streaming medianHard
- Trapping Rain Water in 2D Elevation Mapgraph frontier · Dijkstra · expanded statesHard
- Maximum Courses Taken Within Deadlinesscheduling · sorted events · heapHard
- Minimum Interval to Include Each Queryscheduling · sorted events · heapHard
- IPO Capital Maximizationscheduling · sorted events · heapHard
- Minimum Cost to Hire K Workersgreedy exchange · heap · sortingHard
- Kth Smallest Sum of a Matrix with Sorted Rowssorted frontiers · k-way mergingHard
- Smallest Range Covering Elements from K Listssorted frontiers · k-way mergingHard
- Construct Target Array With Multiple Sumsgreedy exchange · heap · sortingHard
- Minimum Cost to Make at Least One Valid Path in a Gridgraph frontier · Dijkstra · expanded statesHard
- The Skyline Problemscheduling · sorted events · heapHard
- Dynamic Stream Median with Explicit Deletionstwo heaps · streaming medianHard
- Minimum Cost to Reach Destination Within Time Limitgraph frontier · Dijkstra · expanded statesHard
- Leftmost Meeting Building Queryscheduling · sorted events · heapHard
- Least Frequently Used Cache Systemstateful priority queueHard
- Dinner Plate Stacksstateful priority queueHard
- Reachable Nodes in Subdivided Graphgraph frontier · Dijkstra · expanded statesHard
- Kth Smallest Product of Two Sorted Arrayssorted frontiers · k-way mergingHard
- Shortest Path Visiting All Nodesmulti-source BFS · visited bitmaskHard
- Critical and Pseudo-Critical Edges in Minimum Spanning Treeminimum spanning tree · DSU · edge classificationHard
- Shortest Path in a Grid with Obstacles EliminationBFS · resource statesHard
- Maximum Building Height Under Restrictionssorted restrictions · bidirectional propagationHard
- Cut Off Trees for Golf EventBFS · ordered grid targetsHard
- Smallest Sufficient Teambitmask DP · minimum set coverHard
- Fully Persistent Leftist Heap with Branching and Meldpersistent heap · structural sharing · meldVery hard
- Implement a Fibonacci Min-Heap with HandlesFibonacci heap · consolidation · decrease-key · cascading cuts · amortized analysisVery hard