Merge-Sort
LeetCode 4099: Minimum Operations to Sort With Locked Indices
·3 mins
LeetCode
Medium
Array
Merge-Sort
Greedy
LeetCode 4099 note: the swaps needed equal the inversion count; every locked position some element must cross has to be unlocked, so count those, compare with k, and add the inversions counted with merge sort
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
LeetCode 23: Merge k Sorted Lists
·4 mins
LeetCode
Hard
Linked-List
Heap
Merge-Sort
Divide-and-Conquer
LeetCode 23 note: a heap that holds only k heads, and divide-and-conquer pairwise merging
LeetCode 493: Reverse Pairs
·4 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Two-Pointers
Counting
LeetCode 493 note: when the counting condition differs from the sort order, scan first, then merge
LeetCode 4051: Count Subarrays with Distant Sums
·5 mins
LeetCode
Hard
Merge-Sort
Prefix-Sum
Binary-Indexed-Tree
Biweekly-Contest
LeetCode 4051 note: prefix sums, complement counting, range counting, and the k = 0 edge case
LeetCode 2426: Number of Pairs Satisfying Inequality
·3 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Two-Pointers
Counting
LeetCode 2426 note: simplify the inequality, then decide whether the matches form a prefix or a suffix
LeetCode LCR 170: Count Inversions (Sword Offer 51)
·3 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Counting
LCR 170 note: count inversions during the merge step
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 88: Merge Sorted Array
·3 mins
LeetCode
Easy
Two-Pointers
Merge-Sort
LeetCode 88 note: merge from the back with O(1) extra space
LeetCode 315: Count of Smaller Numbers After Self
·4 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Binary-Indexed-Tree
Counting
LeetCode 315 note: merge sort with indices, plus a BIT solution
LeetCode 21: Merge Two Sorted Lists
·3 mins
LeetCode
Easy
Linked-List
Two-Pointers
Merge-Sort
LeetCode 21 note: the dummy node, and why Python assignment is not a copy
LeetCode 327: Count of Range Sum
·3 mins
LeetCode
Hard
Merge-Sort
Divide-and-Conquer
Prefix-Sum
Binary-Indexed-Tree
LeetCode 327 note: prefix sums plus merge sort counting with two pointers bounding a range, and a log of retyping it over a dozen times