Sorting
LeetCode 452: Minimum Number of Arrows to Burst Balloons
·2 mins
LeetCode
Medium
Array
Greedy
Sorting
LeetCode 452 note: sort by end and shoot at the end; only a balloon starting after the arrow needs a new one, and touching ends count as overlapping
LeetCode 314: Binary Tree Vertical Order Traversal
·2 mins
LeetCode
Medium
Hash-Table
Tree
Depth-First-Search
Breadth-First-Search
Sorting
Binary-Tree
LeetCode 314 note: BFS with a column index; BFS is what guarantees top-to-bottom within a column and left-to-right within a row
Bucket Sort and the Pigeonhole Principle
·2 mins
Algorithm
Bucket-Sort
Pigeonhole-Principle
Sorting
Split the value range into n - 1 buckets; the largest gap can never fall inside one bucket, so keeping each bucket’s minimum and maximum finds the maximum adjacent difference in linear time
Two Pointers
·9 mins
Algorithm
Two-Pointers
String
Sorting
Converging pointers, one pointer per sequence, skipping blanks to compare positions, counting pairs after sorting, and the in-place write pointer
Merge Sort and Divide-and-Conquer Counting
·7 mins
Algorithm
Merge-Sort
Divide-and-Conquer
Sorting
Counting
Merge sort templates, where to count in inversion-style problems, the linked list version, and common mistakes
Greedy
·9 mins
Algorithm
Greedy
Sorting
Intervals
Sort then scan, intervals sorted by right end, left and right passes, pairing and parity invariants, adjacent differences, and “remove what exceeds the average”, each with why greedy is correct
LeetCode 912: Sort an Array
·3 mins
LeetCode
Medium
Sorting
Merge-Sort
Divide-and-Conquer
LeetCode 912 note: hand-written merge sort and the two bugs I hit
LeetCode 253: Meeting Rooms II
·2 mins
LeetCode
Medium
Heap
Sorting
Intervals
Sweep-Line
LeetCode 253 note: a heap of end times for running meetings; half-open intervals need <=
LeetCode 2751: Robot Collisions
·3 mins
LeetCode
Hard
Stack
Simulation
Sorting
LeetCode 2751 note: sort by position, push right-moving robots, and let each left-moving robot collide until one side is gone
LeetCode 1998: GCD Sort of an Array
·3 mins
LeetCode
Hard
Math
Number-Theory
Union-Find
Sieve
Sorting
Array
LeetCode 1998 note: numbers in one component can be permuted freely; union each number with its prime factors via SPF, and the array sorts iff each position’s old and new values share a group
LeetCode 2561: Rearranging Fruits
·2 mins
LeetCode
Hard
Greedy
Hash-Table
Sorting
LeetCode 2561 note: every value’s total must be even; sort the excess, and each cheap half item swaps with an expensive one at min(its value, 2 × global minimum)
LeetCode 987: Vertical Order Traversal of a Binary Tree
·2 mins
LeetCode
Hard
Tree
Binary-Tree
Bfs
Sorting
LeetCode 987 note: collect (col, row, val) triples, sort them, and group by column