Merge-sort

10 articles

dsa1 min read

Reverse Pairs — Merge Sort / BIT

Count pairs (i,j) where i<j and nums[i] > 2*nums[j]. Modified merge sort: during merge, count pairs across left/right halves.

Read →
dsa1 min read

Count of Range Sum — Merge Sort / BIT

Count subarray sums within [lower, upper]. Use prefix sums and merge sort: during merge count pairs of prefix sums with difference in range.

Read →
dsa2 min read

Google — Count Inversions (Modified Merge Sort)

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.

Read →