Connect Ropes with Minimum Cost
Connect ropes with minimum cost using greedy approach with heap
Find K Largest Elements
Find the k largest elements from an unsorted array
Find K Smallest Elements
Find the k smallest elements from an unsorted array
Furthest Building You Can Reach
Find furthest building reachable using optimal allocation of bricks and ladders
Kth Largest Element in an Array
Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.
Kth Largest Element in Array
Find the kth largest element in an unsorted array
Kth Smallest Element in Sorted Matrix
Find kth smallest element in row and column sorted matrix using heap
Maximize Sum After K Negations
Maximize array sum by flipping signs of k elements using greedy heap approach
Meeting Rooms II
Find minimum number of meeting rooms required using heap
Merge K Sorted Arrays
Merge k sorted arrays into one sorted array using heap
Merge k Sorted Linked Lists
Merge k sorted linked lists into one sorted linked list
Minimum Number of Refueling Stops
Find minimum refueling stops to reach target using greedy max-heap approach
Minimum Spanning Tree (MST): Kruskal vs Prim (DSU)
Learn what a minimum spanning tree is + MST algorithm steps. Kruskal (Union-Find) O(E log E) vs Prim (heap) O(E log V). Practice now.
Network Delay Time (Dijkstra's Algorithm)
Find the time it takes for a signal to reach all nodes in a network using shortest path algorithms
Reduce Array Size to Half
Find minimum removals to reduce array size by half using greedy heap approach
Reorganize String (LC 767) — Greedy Max-Heap
Solve LC 767 with a greedy priority queue (max-heap). Learn the maxFreq ≤ ceil(n/2) condition + proof. O(n log k). Practice now.
Sliding Window Median (LC 480) — Two Heaps, Lazy Delete
Hard LC 480: rolling median via sliding window + two heaps w/ lazy deletion. O(n log k) time, O(k) space. Step-by-step solution—prep now.
Sort Characters by Frequency
Sort characters in string by frequency using heap or bucket sort
Task Scheduler
Schedule tasks with cooling period using greedy approach with heap
Top K Frequent Elements
Given an integer array and k, return the k most frequent elements.
Top K Frequent Elements (LC 347) — Bucket Sort + Heap
Solve LeetCode 347 Top K Frequent Elements (Medium) with frequency map + bucket sort O(n) or min-heap O(n log k). Step-by-step for interviews.
Ugly Number II (LC 264) — Min-Heap + HashSet (Medium)
What is an ugly number? Solve n-th ugly number (2,3,5) with PriorityQueue + HashSet dedupe. O(n log n). Step-by-step—practice now.