Number of Inversions

Problem Statement

Given an array of integers. Find the Inversion Count in the array.

Inversion Count: For an array, inversion count indicates how far (or close) the array is from being sorted. If the array is already sorted then the inversion count is 0. If an array is sorted in the reverse order then the inversion count is the maximum. Formally, two elements a[i] and a[j] form an inversion if a[i] > a[j] and i < j.

Intuition

Approach :

Sort the array and check

2 3 4 5     1 2 3
Check that 2 is greater than 1 so 2 3 4 5 all greater than 1
So on 
We use Merge sort for this 

https://www.codingninjas.com/studio/problems/number-of-inversions_6840276?utm_source=striver&utm_medium=website&utm_campaign=a_zcoursetuf&leftPanelTabValue=PROBLEM

https://www.youtube.com/watch?v=AseUmwVNaoY&ab_channel=takeUforward

Approach 1:

Approach 2:

Approach 3:

Approach 4:

Similar Problems

Last updated