Back to DSA
Merge Sort - Count Inversions
hardAn 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:
6Hints
1234567