Meeting Rooms (Can Attend All Meetings)
Meeting Rooms (LeetCode 252): sort meetings by start and check that none overlaps the previous one. O(n log n), Python/Java/C++.
150 notes tagged
Meeting Rooms (LeetCode 252): sort meetings by start and check that none overlaps the previous one. O(n log n), Python/Java/C++.
H-Index (LeetCode 274) via sorting: sort citations descending and find the largest i where citations[i] >= i+1. O(n log n), Python/Java/C++.
Wiggle Sort II (LeetCode 324): strict nums[0] < nums[1] > nums[2]... via sorting and interleaving the two halves in reverse. O(n log n), Python/Java/C...
Relative Sort Array (LeetCode 1122): sort by the order defined in a second array, with the rest sorted ascending. O(n log n), Python/Java/C++.
Kth Largest Element (LeetCode 215) via sorting: sort and index from the end in O(n log n), with a note on the O(n)-average quickselect alternative.
Sort Characters By Frequency (LeetCode 451): count characters, then sort by descending frequency and rebuild the string. O(n + k log k), Python/Java/C...
Custom Sort String (LeetCode 791): sort one string by the character priority defined in another, using a rank map. O(n log n) or O(n), Python/Java/C++...
Largest Number (LeetCode 179): sort numbers by a custom pairwise rule (a+b vs b+a) to form the biggest concatenation. O(n log n), Python/Java/C++.
Merge Intervals (LeetCode 56): sort by start, then merge overlapping intervals in one pass. O(n log n), with Python, Java and C++ code.
Sort an Array (LeetCode 912): how to use built-in sorts and custom comparators in Python, Java and C++, including ascending, descending and key-based...
Bucket sort explained: scatter elements into buckets by range, sort each bucket, then concatenate. O(n) average for uniform data, in Python, Java and...