Close
Topic list
Count Inversions
MEDIUM
40 mins
Sorting
Arrays
Topics (Covered in this problem)
Problem solved
Skill meter
Sorting
-
-
Arrays
-
-
Other topics
Problem solved
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

# Count Inversions

Contributed by
Deep Mavani
Medium
0/80
Avg time to solve 40 mins
Success Rate 55 %
Share

## Problem Statement

#### An inversion is defined for a pair of integers in the array/list when the following two conditions are met.

``````A pair ('ARR[i]', 'ARR[j]') is said to be an inversion when:

1. 'ARR[i] > 'ARR[j]'
2. 'i' < 'j'

Where 'i' and 'j' denote the indices ranging from [0, 'N').
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images )
##### Sample Input 1 :
``````3
3 2 1
``````
##### Sample Output 1 :
``````3
``````
##### Explanation of Sample Output 1:
``````We have a total of 3 pairs which satisfy the condition of inversion. (3, 2), (2, 1) and (3, 1).
``````
##### Sample Input 2 :
``````5
2 5 1 3 4
``````
##### Sample Output 2 :
``````4
``````
##### Explanation of Sample Output 1:
``````We have a total of 4 pairs which satisfy the condition of inversion. (2, 1), (5, 1), (5, 3) and (5, 4).
``````
Auto
Console