heap priority queue
heap priority queue is one of the most repeated interview dimensions. Start with edge-safe fundamentals, then move into pattern-level trade-offs.
Interview Signal
Frequently tests problem modeling, edge handling, and verbal clarity.
Common Pitfall
Template-only answers break under follow-up questioning.
Practice Strategy
Practice in 3-5 problem rounds and always review complexity alternatives.
Recommended Progression
High-Pressure Round
Merge k Sorted Lists
Merge k Sorted Lists requires efficiently combining multiple sorted linked lists into one using pointers and priority qu…
Kth Largest Element in an Array
Find the kth largest element in an unsorted array using optimal approaches like Quickselect or heaps.
The Skyline Problem
The Skyline Problem requires calculating a city's silhouette using array manipulation and divide-and-conquer techniques …
Sliding Window Maximum
Solve the "Sliding Window Maximum" problem using efficient techniques like the sliding window, deque, and priority queue…
Ugly Number II
Find the nth ugly number, where ugly numbers have prime factors limited to 2, 3, and 5.
Find Median from Data Stream
Implement a MedianFinder class that supports adding numbers and finding the median from a data stream.
Top K Frequent Elements
Find the k most frequent elements from an array using efficient algorithms like hashing and sorting.
Design Twitter
Design Twitter requires implementing post, follow, unfollow, and news feed retrieval using linked-list pointer manipulat…
Find K Pairs with Smallest Sums
Find K Pairs with Smallest Sums combines arrays and heap usage to select the smallest sum pairs efficiently.
Kth Smallest Element in a Sorted Matrix
Find the kth smallest element in a sorted n x n matrix using efficient binary search or heap strategies for optimized me…
Trapping Rain Water II
Solve Trapping Rain Water II using breadth-first search and priority queues for efficient water trapping in a matrix.
Strong Password Checker
The Strong Password Checker problem challenges you to optimize password strength while minimizing steps using greedy alg…
Sort Characters By Frequency
Sort Characters By Frequency requires counting characters efficiently and rearranging a string in descending frequency o…
Sliding Window Median
Compute the median for each sliding window of size k in an array using efficient array scanning and hash lookup techniqu…
IPO
Maximize total capital by selecting up to k projects, based on initial capital and project profits using a greedy strate…
Relative Ranks
Solve Relative Ranks by sorting scores with original indices, then writing medal labels or numeric places back in answer…
Task Scheduler
Task Scheduler is solved by counting task frequencies and computing how cooldown gaps force idle slots around the most f…
Course Schedule III
Solve the 'Course Schedule III' problem with a greedy approach involving course selection and validation of constraints.
Smallest Range Covering Elements from K Lists
Find the minimal range covering at least one number from each of k sorted lists using array scanning and hash lookup eff…
Find K Closest Elements
Identify the k integers closest to a target x in a sorted array using binary search and two-pointer strategies efficient…
Split Array into Consecutive Subsequences
Verify if it's possible to split a sorted array into consecutive subsequences of length 3 or more.
Cut Off Trees for Golf Event
Determine the minimum steps to cut all trees in a forest matrix in ascending height order using BFS traversal and priori…
Top K Frequent Words
Solve Top K Frequent Words by counting each word, then ordering ties alphabetically so frequency wins before lexicograph…
Kth Largest Element in a Stream
Find the kth largest element in a dynamic stream using binary-tree traversal and efficient state tracking with a min-hea…
Network Delay Time
Find the minimum time for a signal to travel to all nodes in a directed graph or determine if it's impossible.
Reorganize String
Reorganize a string so that no two adjacent characters are the same, if possible, using a greedy approach.
Swim in Rising Water
Solve the problem of swimming through a grid of rising water with a binary search on the valid answer space.
K-th Smallest Prime Fraction
Find the k-th smallest fraction from a sorted array of unique primes using a binary search over the answer space.
Cheapest Flights Within K Stops
Find the cheapest flight from a source to a destination with at most K stops using graph traversal techniques efficientl…
Exam Room
Simulate an exam room where each student chooses a seat maximizing distance to others, using design plus heap structures…
Minimum Cost to Hire K Workers
Find the minimum cost to hire exactly k workers based on quality and wage expectations in this challenging greedy proble…
Shortest Subarray with Sum at Least K
Find the shortest subarray with a sum of at least k using binary search and sliding window techniques.
Minimum Number of Refueling Stops
Determine the minimum number of refueling stops needed to reach a target using dynamic programming and greedy strategies…
Reachable Nodes In Subdivided Graph
The Reachable Nodes In Subdivided Graph problem requires efficiently finding the reachable nodes using graph traversal a…
Sort an Array
Sort an array using an optimal algorithm, focusing on time and space complexity considerations.
K Closest Points to Origin
Find the k closest points to the origin in a 2D plane using array operations and Euclidean distance calculations efficie…
Last Stone Weight
In the 'Last Stone Weight' problem, we smash the two heaviest stones until one remains, using heaps or sorting.
Distant Barcodes
Rearrange barcodes in an array so that no two adjacent elements are equal, using a greedy approach and hash table for ef…
Car Pooling
Determine if a car can handle multiple trips without exceeding its capacity using array sorting and event simulation tec…
Dinner Plate Stacks
Design a system that manages dinner plate stacks using stack-based state management, handling dynamic plate placement an…
Minimum Moves to Move a Box to Their Target Location
Solve the minimum moves to push a box to its target using BFS and priority handling in a grid-based warehouse layout eff…
Search Suggestions System
Design a search suggestion system that provides the top three lexicographically smallest products matching a search word…
The K Weakest Rows in a Matrix
Find the k weakest rows in a binary matrix where rows contain soldiers and civilians, using sorting and binary search te…
Reduce Array Size to The Half
This problem asks to minimize the set of integers removed to reduce an array's size to at least half by removing occurre…
Maximum Number of Events That Can Be Attended
Maximize the number of events you can attend given their start and end days using a greedy strategy.
Construct Target Array With Multiple Sums
This problem requires constructing a target array from an array of ones, using multiple sum operations and a priority qu…
Minimum Cost to Make at Least One Valid Path in a Grid
Determine the minimum cost to create at least one valid path from the top-left to bottom-right in a directional grid.
Maximum Performance of a Team
Maximize the performance of a team by selecting up to k engineers with the highest performance based on speed and effici…
Pizza With 3n Slices
Maximize your pizza slice sum from a 3n-sized circular array using state transition dynamic programming efficiently.
Longest Happy String
Solve the "Longest Happy String" problem using a greedy approach with validation of invariants for constructing the long…
Diagonal Traverse II
Traverse a jagged 2D array diagonally by grouping elements with equal row and column sums efficiently using sorting and …
Constrained Subsequence Sum
Solve the Constrained Subsequence Sum problem using dynamic programming, sliding window, and priority queues to maximize…
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Find the longest subarray with elements whose absolute difference is within a specified limit using a sliding window app…
Find the Kth Smallest Sum of a Matrix With Sorted Rows
Find the kth smallest sum in a matrix with sorted rows using binary search and a heap-based approach.
Maximum Product of Two Elements in an Array
Find the maximum product of two elements in an array by carefully selecting indices and leveraging sorting for efficienc…
Avoid Flood in The City
This problem asks you to avoid flooding by deciding when to dry lakes between rain events.
Max Value of Equation
Max Value of Equation asks to find the maximum value of a specific equation on a set of 2D points using sliding window t…
Path with Maximum Probability
Find the path with the highest success probability in a graph from a start node to an end node, using edge probabilities…
Find Servers That Handled Most Number of Requests
Given k servers and a series of requests, find the busiest server(s) using greedy strategies and efficient server tracki…
Path With Minimum Effort
Find the minimum effort required to travel from the top-left to the bottom-right of a grid, considering height differenc…
Furthest Building You Can Reach
Furthest Building You Can Reach explores a greedy approach with heap-based optimization to find the maximum reachable bu…
Sell Diminishing-Valued Colored Balls
Maximize total value by greedily selling diminishing-valued colored balls based on inventory and customer orders.
Minimize Deviation in Array
Given a positive integer array, repeatedly double or halve elements to minimize the difference between its largest and s…
Stone Game VI
Determine the winner in Stone Game VI using a greedy strategy that accounts for each stone's dual value impact on Alice …
Delivering Boxes from Storage to Ports
Optimize the minimum number of trips to deliver boxes to ports under strict ship constraints using dynamic programming t…
Jump Game VI
Jump Game VI challenges you to maximize your score while jumping through an array using state transition dynamic program…
Maximum Number of Eaten Apples
Maximize apples eaten by choosing the best apples first, considering their rot days and available days to eat them.
Find Kth Largest XOR Coordinate Value
Compute the kth largest XOR coordinate in a 2D matrix using prefix sums, bit manipulation, and optimized selection techn…
Maximum Score From Removing Stones
Maximize the score in a solitaire game by optimally removing stones from three piles with a greedy approach.
Car Fleet II
Car Fleet II involves calculating collision times between cars traveling at different speeds along a one-lane road using…
Number of Restricted Paths From First to Last Node
Solve the problem of finding the number of restricted paths in a weighted undirected graph, leveraging graph algorithms …
Maximum Average Pass Ratio
Maximize the average pass ratio by assigning extra guaranteed-passing students using a greedy heap strategy for optimal …
Number of Orders in the Backlog
Determine the total number of unfulfilled buy and sell orders using heaps to simulate backlog processing efficiently in …
Finding MK Average
Find the MKAverage of a stream of integers using a queue-driven approach with efficient state management.
Single-Threaded CPU
Simulate task processing with a single-threaded CPU by sorting and prioritizing tasks based on arrival and processing ti…
Seat Reservation Manager
Manage seat reservations efficiently using a design combining priority queue to always return the lowest available seat …
Minimum Interval to Include Each Query
Find the smallest interval containing each query efficiently using binary search.
Get Biggest Three Rhombus Sums in a Grid
Find the three largest distinct rhombus sums from a given grid using array and math techniques.
Process Tasks Using Servers
Assign tasks to servers efficiently using arrays and heaps, resolving ties by weight and index while tracking availabili…
Design Movie Rental System
Implement a movie rental system with efficient search, rent, drop, and report operations using arrays and hash lookups.
The Number of the Smallest Unoccupied Chair
Solve The Number of the Smallest Unoccupied Chair by sorting arrivals and managing freed seats before each new assignmen…
Remove Stones to Minimize the Total
Minimize the total stones by repeatedly removing half from the largest pile using a greedy heap strategy.
Find the Kth Largest Integer in the Array
This problem asks to find the kth largest integer in an array of string numbers, highlighting sorting and string-based c…
Stock Price Fluctuation
Design an efficient algorithm for managing stock price fluctuations with incorrect and unordered data in a data stream.
Two Best Non-Overlapping Events
Maximize the total value of at most two non-overlapping events using state transition dynamic programming efficiently.
Find Subsequence of Length K With the Largest Sum
Pick the k largest values, then restore their original order to build the maximum-sum subsequence correctly.
Sequentially Ordinal Rank Tracker
Track rankings of locations with names and scores, adding new locations and retrieving top-ranked ones efficiently.
K Highest Ranked Items Within a Price Range
Use BFS to rank reachable shop items by distance, price, row, and column, then return the best k coordinates.
Minimum Difference in Sums After Removal of Elements
Minimize the difference between sums after removing n elements from a 3n array by dividing the remaining elements into t…
Construct String With Repeat Limit
Construct a lexicographically largest string from a given string with no letter appearing more than a repeatLimit times …
Minimum Operations to Halve Array Sum
Minimize operations to halve an array's sum using greedy choices and heap data structures.
Largest Number After Digit Swaps by Parity
Maximize a number by swapping digits of the same parity using sorting and priority queue techniques efficiently.
Maximum Product After K Increments
Maximize the product of an array after performing up to k increments using a greedy approach with heap optimization.
Maximum Total Importance of Roads
Assign unique values to cities to maximize the total importance of all roads using greedy selection based on city connec…
Minimum Obstacle Removal to Reach Corner
Find the minimum obstacles to remove in a 2D grid to reach the bottom-right corner using BFS graph traversal techniques.
Minimum Sum of Squared Difference
Calculate the minimum sum of squared differences between two arrays using limited modifications and binary search techni…
Minimum Amount of Time to Fill Cups
Determine the minimum seconds to fill cups of cold, warm, and hot water using a greedy selection strategy and invariant …
Smallest Number in Infinite Set
Design a data structure to handle the smallest missing element in an infinite set, with the ability to add and remove el…
Max Sum of a Pair With Equal Sum of Digits
Find the maximum sum of two numbers with equal digit sums in a given array of positive integers.
Query Kth Smallest Trimmed Number
Solve the Query Kth Smallest Trimmed Number problem by efficiently trimming and sorting strings in an array to answer qu…
Minimum Deletions to Make Array Divisible
Find the minimum number of deletions to make the smallest element in nums divide all elements of numsDivide.
Design a Number Container System
Learn to implement a Number Container System using hash tables and design techniques to efficiently track numbers and in…
Design a Food Rating System
Design a food rating system that tracks and updates ratings of foods, finding the highest rated items by cuisine.
Make Array Zero by Subtracting Equal Amounts
Minimize operations to make all array elements zero by subtracting equal amounts in each operation.
Find the K-Sum of an Array
Find the K-Sum of an Array requires computing the kth largest subsequence sum in an array using sorting and heap techniq…
Maximum Number of Robots Within Budget
Determine the maximum number of consecutive robots you can operate without exceeding a given budget using efficient bina…
Meeting Rooms III
Determine which meeting room holds the most meetings by simulating room assignments with precise time tracking.
Divide Intervals Into Minimum Number of Groups
Determine the minimum number of non-overlapping groups for a set of intervals using precise two-pointer scanning logic.
Longest Uploaded Prefix
Calculate the longest continuous uploaded prefix in a video stream efficiently using a mix of binary search and data str…
Next Greater Element IV
Find the second greater integer for each element in an array using binary search and monotonic stack techniques.
Most Popular Video Creator
Identify the most popular video creator by summing views and selecting their top-viewed video with array and hash patter…
Total Cost to Hire K Workers
Optimize the total cost of hiring exactly k workers using a two-pointer approach with invariant tracking and priority qu…
Maximum Star Sum of a Graph
Find the maximum star sum in a graph with specific node values and edges, using greedy algorithms to select the optimal …
Delete Greatest Value in Each Row
Calculate the total of removed maximum values from each row of a matrix, iterating until all columns are deleted efficie…
Maximum Number of Points From Grid Queries
Solve the Maximum Number of Points From Grid Queries problem using two-pointer scanning and invariant tracking.
Reward Top K Students
Calculate top K student scores by scanning reports and using hash tables for positive and negative word lookups efficien…
Maximal Score After Applying K Operations
Maximize your score by applying exactly k operations on an array using greedy selection and heap optimization techniques…
Time to Cross a Bridge
Time to Cross a Bridge involves simulating worker movements using arrays and heaps to determine when the last worker cro…
Maximum Subsequence Score
Maximize the score of a subsequence by selecting indices based on nums1 and nums2, using a greedy approach and sorting.
Put Marbles in Bags
The "Put Marbles in Bags" problem challenges you to distribute marbles into bags for maximum score difference using gree…
Take Gifts From the Richest Pile
Take Gifts From the Richest Pile uses a heap to simulate the process of taking gifts from the richest pile over a number…
Minimum Time to Visit a Cell In a Grid
Compute the fastest path in a grid where each cell has a minimum time requirement using BFS and priority queue technique…
Find Score of an Array After Marking All Elements
The problem involves marking elements in an array and calculating the score based on adjacent elements.
Mice and Cheese
In 'Mice and Cheese', you must maximize the total reward of two mice eating cheese while respecting their preferences an…
Minimum Number of Visited Cells in a Grid
Determine the minimum number of cells to visit in a grid using state transition dynamic programming and efficient traver…
Design Graph With Shortest Path Calculator
Implement a dynamic weighted directed graph with efficient shortest path queries and edge additions in real time.
Minimum Cost of a Path With Special Roads
Find the minimum cost path between two points, using special roads or direct moves in a 2D space.
Sum in a Matrix
Calculate the maximum score by repeatedly removing the largest elements from each row of a 2D matrix efficiently using s…
Modify Graph Edge Weights
Modify Graph Edge Weights is a graph problem where you adjust edge weights to match a target shortest path distance.
Continuous Subarrays
Count all continuous subarrays efficiently using sliding window with running max-min state tracking for array consistenc…
Find the Safest Path in a Grid
Find the Safest Path in a Grid uses binary search and BFS to maximize path safeness from thieves in a grid.
Maximum Elegance of a K-Length Subsequence
Maximize elegance of a k-length subsequence from a list of items with profits and categories.
Maximum Spending After Buying Items
Maximize spending by carefully choosing the right items across multiple shops over m * n days.
Find Building Where Alice and Bob Can Meet
Determine the leftmost building where Alice and Bob can meet using a binary search over valid move sequences.
Minimum Number of Coins for Fruits
Calculate the minimum coins to buy fruits using state transition dynamic programming while handling rewards and purchase…
Number of Possible Sets of Closing Branches
Calculate all valid sets of branch closures while keeping remaining branches within maxDistance using bitmask and graph …
Find Number of Coins to Place in Tree Nodes
Determine the exact number of coins to place on each tree node using subtree cost products and DFS tracking.
Minimum Number Game
The Minimum Number Game involves simulating moves by Alice and Bob on an array, sorting elements and appending them to a…
Divide an Array Into Subarrays With Minimum Cost II
This problem asks to divide an array into subarrays with a minimal cost and certain constraints on subarray positions.
Earliest Second to Mark Indices II
This problem asks to determine the earliest second at which all indices in an array can be marked using a sequence of op…
Minimum Operations to Exceed Threshold Value II
Calculate the fewest operations to make every array element exceed a threshold using a min-heap simulation strategy effi…
Mark Elements on Array by Performing Queries
Efficiently mark elements in an array based on queries using scanning plus hash lookup to track marked indices and compu…
Replace Question Marks in String to Minimize Its Value
Minimize the cost of a string with '?' characters by replacing them with letters in lexicographical order while minimizi…
Most Frequent IDs
Track the most frequent ID after each update in a dynamic collection of IDs with changing frequencies.
Minimum Time to Visit Disappearing Nodes
Determine the minimum time to visit each node in a disappearing-node graph using arrays, graphs, and priority queues eff…
Find Edges in Shortest Paths
Use two Dijkstra runs to mark exactly which edges can appear on at least one shortest path from 0 to n - 1.
Lexicographically Minimum String After Removing Stars
Find the lexicographically smallest string by removing stars using stack-based state management and careful character se…
Final Array State After K Multiplication Operations I
Solve the problem of determining the final state of an array after multiple multiplication operations using a priority q…
Final Array State After K Multiplication Operations II
Optimize the final state of an array after performing k multiplication operations with priority queues.
K-th Nearest Obstacle Queries
Solve the K-th nearest obstacle query problem using array and heap (priority queue) techniques to find distances efficie…
Find a Safe Walk Through a Grid
Determine if you can safely traverse a binary grid from top-left to bottom-right using limited health points.
Minimum Number of Seconds to Make Mountain Height Zero
Determine the minimum seconds required to reduce a mountain to zero height using simultaneous workers efficiently.
Find X-Sum of All K-Long Subarrays I
Compute the x-sum of every subarray of length k efficiently using array scanning combined with hash lookup techniques.
Find X-Sum of All K-Long Subarrays II
Calculate the x-sum for every k-length subarray using efficient array scanning and hash-based counting techniques.
Find Minimum Time to Reach Last Room I
Find Minimum Time to Reach Last Room I challenges you to determine the minimum time to travel in a dungeon with a grid l…
Find Minimum Time to Reach Last Room II
Calculate the minimum time to reach the last room in a grid with alternating move times using array and graph patterns.
Zero Array Transformation III
Zero Array Transformation III requires removing the minimum number of queries to make all elements zero using greedy val…
Digit Operations to Make Two Integers Equal
Transform n into m using allowed digit operations without creating primes, applying math and graph strategies efficientl…
Design Task Manager
Design a Task Manager that can efficiently handle task management operations such as adding, editing, executing, and rem…
Maximum Sum With at Most K Elements
Find the maximum sum by selecting at most k elements from a 2D matrix respecting per-row limits using a greedy strategy.
Choose K Elements With Maximum Sum
Choose K Elements With Maximum Sum involves sorting and selecting elements based on a specific rule, applying array plus…
Minimum Operations to Make Elements Within K Subarrays Equal
Compute the minimum operations to ensure at least k non-overlapping subarrays of size x have all equal elements efficien…
Minimum Pair Removal to Sort Array I
This problem asks for the minimum number of operations to make an array non-decreasing by removing pairs of elements.
Minimum Pair Removal to Sort Array II
The problem asks to find the minimum number of operations to make an array non-decreasing by removing pairs of elements.
Maximize Y‑Sum by Picking a Triplet of Distinct X‑Values
Select three distinct x-values from arrays to maximize the sum of their corresponding y-values efficiently using hashing…
Minimum Time to Transport All Individuals
Find the minimum time to transport individuals across a river with dynamic environmental conditions and boat capacity.
Minimum Time to Reach Destination in Directed Graph
The problem involves finding the minimum time to reach the destination in a directed graph with time-dependent edges.
Power Grid Maintenance
Determine which power stations remain connected after maintenance using array scanning and hash lookups to track compone…
Network Recovery Pathways
Find the maximum recovery cost of valid paths in a directed acyclic graph where some nodes are offline.
Related Patterns
Array plus Divide and Conquer
35 linked problems
Array scanning plus hash lookup
30 linked problems
Greedy choice plus invariant validation
30 linked problems
Binary search over the valid answer space
19 linked problems
State transition dynamic programming
11 linked problems
Array plus Sorting
10 linked problems