DSAWiser

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

  1. Open a question in the editor and read the statement, inputs, and expected output. Predict the result for a small example before writing code.
  2. Write a solution and run the examples. If a result differs from your prediction, reduce the input until you can follow each step.
  3. 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 total

Open a question in the editor to read its statement and examples. Sign in to practice.

  1. Parent Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  2. Left Child Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  3. Right Child Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  4. Parent and Children Indices in a 1-Indexed Binary Heapheap indexing · complete binary treeBasic
  5. Is Valid Heap Node Index and Boundary Checkheap indexing · complete binary treeBasic
  6. Check if a Node is a Leaf in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  7. Last Non-Leaf Node Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  8. Sibling Node Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  9. Binary Heap Height from Element Countheap indexing · complete binary treeBasic
  10. Count of Leaf Nodes in a Binary Heapheap indexing · complete binary treeBasic
  11. Node Level in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  12. Maximum Nodes at a Given Heap Levelheap indexing · complete binary treeBasic
  13. Minimum Elements for a Given Binary Heap Heightheap indexing · complete binary treeBasic
  14. Maximum Elements for a Given Binary Heap Heightheap indexing · complete binary treeBasic
  15. First Leaf Node Index in a 0-Indexed Binary Heapheap indexing · complete binary treeBasic
  16. Verify Min-Heap Property at a Single Nodeheap order · validationBasic
  17. Verify Max-Heap Property at a Single Nodeheap order · validationBasic
  18. Validate Entire Array as Min-Heapheap order · validationBasic
  19. Validate Entire Array as Max-Heapheap order · validationBasic
  20. First Violation Index of Min-Heap Propertyheap order · validationBasic
  21. First Violation Index of Max-Heap Propertyheap order · validationBasic
  22. Peek Minimum Element in a Min-Heapheap extrema · array traversalBasic
  23. Peek Maximum Element in a Max-Heapheap extrema · array traversalBasic
  24. Find Maximum Element in a Min-Heapheap extrema · array traversalBasic
  25. Find Minimum Element in a Max-Heapheap extrema · array traversalBasic
  26. Single Sift-Up Step in a 0-Indexed Min-Heapsift-up · parent comparisonsBasic
  27. Single Sift-Up Step in a 0-Indexed Max-Heapsift-up · parent comparisonsBasic
  28. Smallest Child Index in a 0-Indexed Min-Heapsift-down · deterministic repairBasic
  29. Largest Child Index in a 0-Indexed Max-Heapsift-down · deterministic repairBasic
  30. Single Sift-Down Step in a 0-Indexed Min-Heapsift-down · deterministic repairBasic
  31. Single Sift-Down Step in a 0-Indexed Max-Heapsift-down · deterministic repairBasic
  32. Priority Queue Peek Highest Priority Tasktask priority · comparatorsBasic
  33. Compute a Radix-Heap Bucket Indexradix heap helper · XOR · bit lengthBasic
  34. Check That Corrupted Item Keys Never Decreasenested scan · key inequalityBasic
  35. Full Sift-Up in a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
  36. Full Sift-Up in a 0-Indexed Max-Heapsift-up · parent comparisonsEasy
  37. Count Swaps During Sift-Up in a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
  38. Full Sift-Down from Root in a 0-Indexed Min-Heapsift-down · deterministic repairEasy
  39. Full Sift-Down from Root in a 0-Indexed Max-Heapsift-down · deterministic repairEasy
  40. Insert Element into a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
  41. Insert Element into a 0-Indexed Max-Heapsift-up · parent comparisonsEasy
  42. Extract Minimum Element from a 0-Indexed Min-Heapsift-down · deterministic repairEasy
  43. Extract Maximum Element from a 0-Indexed Max-Heapsift-down · deterministic repairEasy
  44. Replace Root in a 0-Indexed Min-Heapsift-down · deterministic repairEasy
  45. Replace Root in a 0-Indexed Max-Heapsift-down · deterministic repairEasy
  46. Decrease Key in a 0-Indexed Min-Heapsift-up · parent comparisonsEasy
  47. Increase Key in a 0-Indexed Max-Heapsift-up · parent comparisonsEasy
  48. Delete Element at Arbitrary Index in a 0-Indexed Min-Heapsift-down · deterministic repairEasy
  49. Build Min-Heap from Unsorted Arraybottom-up heap constructionEasy
  50. Build Max-Heap from Unsorted Arraybottom-up heap constructionEasy
  51. Convert Min-Heap Array to Max-Heap Arraybottom-up heap constructionEasy
  52. Priority Queue Enqueue Task with Prioritytask priority · comparatorsEasy
  53. Kth Largest Element in a Streamtop-k selection · bounded heapEasy
  54. Last Stone Weightgreedy heap simulationEasy
  55. The K Weakest Rows in a Matrixbinary heap · priority queueEasy
  56. Take Gifts From the Richest Pilegreedy heap simulationEasy
  57. Seat Reservation Manager Simulationstateful priority queueEasy
  58. Maximize Sum of Array After K Negationsgreedy heap simulationEasy
  59. Find Subsequence of Length K With the Largest Sumtop-k selection · bounded heapEasy
  60. Sum of Elements Between K1-th and K2-th Smallest Elementsbinary heap · priority queueEasy
  61. Merge Two Binary Max-Heapsbottom-up heap constructionEasy
  62. Smallest Number in Infinite Set Simulationstateful priority queueEasy
  63. Kth Distinct Largest Integertop-k selection · bounded heapEasy
  64. Top K Sum of Speedstop-k selection · bounded heapEasy
  65. Minimum Sum of Squares After K Decrementsgreedy heap simulationEasy
  66. Maximal Score After Applying K Operationsgreedy heap simulationEasy
  67. Least Quality Sum for K Chosen Workerstop-k selection · bounded heapEasy
  68. Minimum Operations to Exceed Threshold Value IIgreedy heap simulationEasy
  69. Implement Mixed Min-Heap Operationsbinary heap · stateful operations · empty queueEasy
  70. Count Comparisons in Bottom-Up Heap Constructionbottom-up heapify · linear construction · comparison countingEasy
  71. Maximum Product of Two Elements in an Arraytop-two scan · arithmeticEasy
  72. Relative Rankssorting · rankingEasy
  73. Make Array Zero by Subtracting Equal Amountsdistinct positive countsEasy
  74. Minimum Amount of Time to Fill Cupscounting · scheduling formulaEasy
  75. Delete Greatest Value in Each Rowrow sorting · column maximaEasy
  76. Sort Array by Increasing Frequencyfrequency counting · sortingEasy
  77. Check if Characters Can Be Reorganized Without Adjacent Duplicatesfrequency feasibility boundEasy
  78. Maximum Units on a Trucksorting · greedy loadingEasy
  79. Nearest Valid Point with Smallest Indexlinear scan · Manhattan distanceEasy
  80. Highest-Rated Food by Cuisinestatic map · comparatorEasy
  81. Minimum Operations to Exceed Threshold Value Ithreshold countingEasy
  82. Ordered-Set Predecessor and Successor in a Small Universebounded ordered set · bit maskEasy
  83. Logical Deletion Event Snapshot Replayevent replay · node identity · logical deletionEasy
  84. Sort an Almost Sorted Arraysorted frontiers · k-way mergingMedium
  85. Minimum Cost to Connect Sticksgreedy heap simulationMedium
  86. Kth Largest Element in an Arraytop-k selection · bounded heapMedium
  87. Kth Smallest Element in an Arraytop-k selection · bounded heapMedium
  88. K Closest Points to Origintop-k selection · bounded heapMedium
  89. Top K Frequent Elementstop-k selection · bounded heapMedium
  90. Minimum Operations to Halve Array Sumgreedy heap simulationMedium
  91. Find K Pairs with Smallest Sumssorted frontiers · k-way mergingMedium
  92. Reduce Array Size to The Halfgreedy heap simulationMedium
  93. Top K Frequent Wordstop-k selection · bounded heapMedium
  94. Kth Smallest Pair Sum Across Two Sorted Arrayssorted frontiers · k-way mergingMedium
  95. Car Pooling Capacity Checkscheduling · sorted events · heapMedium
  96. Minimum Number of Meeting Roomsscheduling · sorted events · heapMedium
  97. Maximum Product After K Incrementsgreedy heap simulationMedium
  98. Kth Smallest Prime Fractionsorted frontiers · k-way mergingMedium
  99. Process Tasks Using Serversscheduling · sorted events · heapMedium
  100. Running Median of an Integer Streamtwo heaps · streaming medianMedium
  101. Maximum Subsequence Scoregreedy exchange · heap · sortingMedium
  102. Kth Smallest Element in a Sorted Matrixsorted frontiers · k-way mergingMedium
  103. Maximum Subarray Sum with Bounded Lengthprefix sums · sliding heap · lazy invalidationMedium
  104. In-Place Heapsort in Ascending Orderheapsort · in-place sorting · heap boundaryMedium
  105. Merge K Sorted Arrayssorted frontiers · k-way mergingMedium
  106. Task Scheduler with Cooldown Intervalscheduling · sorted events · heapMedium
  107. Reorganize String Distance K Feasibilitycooldown scheduling · character countsMedium
  108. K Pairs with Smallest Productssorted frontiers · k-way mergingMedium
  109. Single Source Shortest Path via Dijkstragraph frontier · Dijkstra · expanded statesMedium
  110. Network Delay Timegraph frontier · Dijkstra · expanded statesMedium
  111. Path with Minimum Effortgraph frontier · Dijkstra · expanded statesMedium
  112. Swim in Rising Watergraph frontier · Dijkstra · expanded statesMedium
  113. Single-Threaded CPU Task Processing Orderscheduling · sorted events · heapMedium
  114. Maximum CPU Load During Overlapping Jobsscheduling · sorted events · heapMedium
  115. Frontier Kth Smallest Element in a Multiplication Tablesorted frontiers · k-way mergingMedium
  116. Maximum Average Pass Ratiogreedy heap simulationMedium
  117. Cheapest Flights Within K Stopsgraph frontier · Dijkstra · expanded statesMedium
  118. Longest Happy String Maximum Lengthgreedy heap simulationMedium
  119. Furthest Building You Can Reachgreedy heap simulationMedium
  120. Divide Intervals Into Minimum Number of Groupsscheduling · sorted events · heapMedium
  121. Maximum Number of Events That Can Be Attendedgreedy heap simulationMedium
  122. Stock Price Fluctuation Systemstateful priority queueMedium
  123. Minimum Deletions to Make Character Frequencies Uniquefrequency counts · greedy deletion · optional heapMedium
  124. Recent Tweets Feed Extractionstateful priority queueMedium
  125. Rearrange String with a Cooldown Priority Queuecooldown scheduling · character countsMedium
  126. Maximum Frequency Stackstateful priority queueMedium
  127. Sliding Window Maximum via Lazy Heap Invalidationprefix sums · sliding heap · lazy invalidationMedium
  128. Minimum Cost to Reach Destination with Toll Discountsgraph frontier · Dijkstra · expanded statesMedium
  129. Minimum-Effort Path Through a 3D Gridgraph frontier · Dijkstra · expanded statesMedium
  130. Maximum Subarray Sum with Length Bounded Between K1 and K2prefix sums · sliding heap · lazy invalidationMedium
  131. Meldable Leftist Min-Heap Operationsmeldable leftist heapMedium
  132. Skew Heap Meld Preorder Reconstructionskew heap · recursive meldMedium
  133. Binomial Heap Forest Unionbinomial forest · degree carriesMedium
  134. Fibonacci Heap Cascading Cut SimulationFibonacci heap helper · cascading cutsMedium
  135. Pairing Heap Two-Pass Meld Preorderpairing heap · two-pass meldMedium
  136. Indexed Min-Priority Queue with Change-Key and Deletionindexed heap · stable handles · bidirectional repairMedium
  137. Stable Task Priorities with Updates and Cancellationstable priority queue · lazy invalidation · mutable prioritiesMedium
  138. Split Array into Consecutive Subsequences Validationgreedy exchange · heap · sortingHard
  139. Minimum Number of Refueling Stopsgreedy exchange · heap · sortingHard
  140. Sliding Window Mediantwo heaps · streaming medianHard
  141. Trapping Rain Water in 2D Elevation Mapgraph frontier · Dijkstra · expanded statesHard
  142. Maximum Courses Taken Within Deadlinesscheduling · sorted events · heapHard
  143. Minimum Interval to Include Each Queryscheduling · sorted events · heapHard
  144. IPO Capital Maximizationscheduling · sorted events · heapHard
  145. Minimum Cost to Hire K Workersgreedy exchange · heap · sortingHard
  146. Kth Smallest Sum of a Matrix with Sorted Rowssorted frontiers · k-way mergingHard
  147. Smallest Range Covering Elements from K Listssorted frontiers · k-way mergingHard
  148. Construct Target Array With Multiple Sumsgreedy exchange · heap · sortingHard
  149. Minimum Cost to Make at Least One Valid Path in a Gridgraph frontier · Dijkstra · expanded statesHard
  150. The Skyline Problemscheduling · sorted events · heapHard
  151. Dynamic Stream Median with Explicit Deletionstwo heaps · streaming medianHard
  152. Minimum Cost to Reach Destination Within Time Limitgraph frontier · Dijkstra · expanded statesHard
  153. Leftmost Meeting Building Queryscheduling · sorted events · heapHard
  154. Least Frequently Used Cache Systemstateful priority queueHard
  155. Dinner Plate Stacksstateful priority queueHard
  156. Reachable Nodes in Subdivided Graphgraph frontier · Dijkstra · expanded statesHard
  157. Kth Smallest Product of Two Sorted Arrayssorted frontiers · k-way mergingHard
  158. Shortest Path Visiting All Nodesmulti-source BFS · visited bitmaskHard
  159. Critical and Pseudo-Critical Edges in Minimum Spanning Treeminimum spanning tree · DSU · edge classificationHard
  160. Shortest Path in a Grid with Obstacles EliminationBFS · resource statesHard
  161. Maximum Building Height Under Restrictionssorted restrictions · bidirectional propagationHard
  162. Cut Off Trees for Golf EventBFS · ordered grid targetsHard
  163. Smallest Sufficient Teambitmask DP · minimum set coverHard
  164. Fully Persistent Leftist Heap with Branching and Meldpersistent heap · structural sharing · meldVery hard
  165. Implement a Fibonacci Min-Heap with HandlesFibonacci heap · consolidation · decrease-key · cascading cuts · amortized analysisVery hard