This site uses JavaScript for navigation, themes, and games like 2048. Please enable JavaScript in your browser settings, then reload the page.
11 problems. Click one to open the details.
0/11 solved
1.Kth Smallest Element
Use a max-heap of size k; the top is the kth smallest.
2.Kth Largest Element
Min-heap of size k; top is the kth largest.
3.Sort a K-Sorted Array
Each element is at most k positions away; min-heap of size k+1 sorts in O(n log k).
4.K Closest Numbers
Max-heap by absolute difference to x; keep k closest values.
5.Top K Frequent Elements
Count frequencies, then min-heap of size k by frequency.
6.Frequency Sort
Sort elements by decreasing frequency (max-heap on count).
7.K Closest Points to Origin
Max-heap by squared distance; keep k closest points to (0,0).
8.Connect Ropes with Minimum Cost
Always connect two shortest ropes; cost is sum of lengths.
9.Sum of Elements Between K1 and K2 Smallest
Sum elements strictly between the k1-th and k2-th smallest.
10.Task Scheduler
Min intervals with cooldown using freq greedy/heap.
11.Implement Min Heap
Array heap: sift-up / sift-down for insert and extract-min.