Count of Smaller Numbers After Self [Hard] — Merge Sort
Count elements smaller than each element to its right using a modified merge sort that counts inversions during the merge step.
webcoderspeed.com
10 articles
Count elements smaller than each element to its right using a modified merge sort that counts inversions during the merge step.
Count pairs (i,j) where i<j and nums[i]>2*nums[j] using modified merge sort to count cross-half pairs before merging.
Count the number of range sums that lie in [lower, upper] using a merge sort approach on prefix sums.
Count smaller elements to the right of each element using merge sort with position tracking in O(n log n).
Count subarrays with sum in [lower, upper] using merge sort on prefix sums for O(n log n) complexity.
Sort a linked list in O(n log n) time and O(log n) space using top-down merge sort with fast/slow split.
Sort a linked list in O(n log n) time and O(1) space using bottom-up merge sort with doubling sublist sizes.
Count pairs (i,j) where i<j and nums[i] > 2*nums[j]. Modified merge sort: during merge, count pairs across left/right halves.
Count subarray sums within [lower, upper]. Use prefix sums and merge sort: during merge count pairs of prefix sums with difference in range.
Count the number of inversions in an array (pairs where i < j but arr[i] > arr[j]) using modified merge sort in O(n log n). Google uses this to test deep algorithm understanding.