Data Structures
Sort a Nearly Sorted (K-Sorted) Array
Sort a nearly sorted (k-sorted) array where each element is at most k positions from its place, using a size-(k+1) min-heap in O(n log k). Python/Java...
3 notes tagged
Sort a nearly sorted (k-sorted) array where each element is at most k positions from its place, using a size-(k+1) min-heap in O(n log k). Python/Java...
Meeting Rooms II (LeetCode 253): find the minimum rooms by sorting start and end times separately and sweeping with two pointers. O(n log n), Python/J...
Heap sort explained: build a max-heap, then repeatedly move the max to the end. O(n log n) worst case, in-place, with Python, Java and C++ code.