InterviewBit Academy is now Scaler!
Learn Tech Skills from Scratch @ Scaler EDGE


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


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

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

NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving INVERSIONS on Interview Code Editor
Sign Up
to access hints and editorial solutions for INVERSIONS


Click here to start solving coding interview questions