Small example
Input
arr = [2, 4, 1, 3, 5]
Output
3
Inversions are (2,1), (4,1), (4,3) -> total 3.
Full lesson preview
Count the number of inversions in an array by augmenting merge sort to count cross-pairs.
Problem statement
Task
Examples
Input
arr = [2, 4, 1, 3, 5]
Output
3
Inversions are (2,1), (4,1), (4,3) -> total 3.
Input format
Output format
Constraints
Samples
Input
count_inversions([1, 3, 2])
Output
1
Only inversion is (3,2).