Challenge: Inversion Count in an Array

In this lesson, you will solve the problem of counting the number of inversions in an array.

What is inversion count?

Inversion count represents how far or close an array is from being sorted. If an array is sorted, the inversion count is 0. But if it’s sorted in the reverse order, the inversion count is maximum.

Let’s say there are two elements arr[i], arr[j] of an array int[]arr. If arr[i] > arr[j] where i < j, there is inversion.

For example:

 (9, 5, 6, 11, 8, 10) 

 Number of inversions = 5 

 i-e: (9, 5), (9, 6), (9, 8), (11, 8), (11, 10)

Have a look at the following illustration for a better understanding:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.