Back to DSA

Merge Sort - Count Inversions

hard
Acceptance: 38%
SortingDivide and Conquer

An inversion in an array is any pair of indices (i, j) with i < j where the earlier element is larger than the later one. Given an integer array, count the total number of inversions.

Examples

Example 1:
Input:nums = [3,1,2,5,4]
Output:3
Example 2:
Input:nums = [4,3,2,1]
Output:6

Hints

00:00
1234567