INVERSIONS

Given an array A, count the number of inversions in the array.

Formally speaking, two elements A[i] and A[j] form an inversion if A[i] > A[j] and i < j

Example:

A : [2, 4, 1, 3, 5]
Output : 3

as the 3 inversions are (2, 1), (4, 1), (4, 3).

Interview Code Editor
1398 successful submissions.
Click here to jump start your coding interview preparation