Inversion Count (MergeSort)

Hard

📝 Description

Count inversions in an array (how far it is from being sorted).

Input Format

[a1, a2, ..., an] (array of integers)

Output Format

count (integer)

Constraints

1 ≤ n ≤ 5×10^5

🔍 Sample Input

[8, 4, 2, 1]
            

✅ Sample Output

6
            

Code Editor

Please login to run and submit code.

Shortcuts: Ctrl+Enter to submit, Ctrl+Shift+R to run