 New update is available. Click here to update. Close
Topic list
Reverse Pairs
HARD
50 mins 57 upvotes
Sorting
Topics (Covered in this problem)
Problem solved
Skill meter Sorting
-
-
Other topics
Problem solved
Skill meter Strings
-
- Matrices (2D Arrays)
-
- -
- Binary Search
-
- Stacks & Queues
-
- Trees
-
- Graph
-
- Dynamic Programming
-
- Greedy
-
- Tries
-
- Arrays
-
- 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.

# Reverse Pairs

Hard 0/120
Avg time to solve 50 mins
Success Rate 90 % Share 57 upvotes

## Problem Statement

#### For example :

``````For the array [50, 21, 9], if we follow 1-based indexing, the Reverse Pairs are (1, 2), (1, 3) and (2, 3). Thus, the total count i.e. the answer becomes 3.
``````

#### Note :

``````A single index of the pair (i, j) can be used multiple times.
``````
Detailed explanation ( Input/output format, Notes, Constraints, Images ) ##### Sample Input 1 :
``````1
6
1 2 3 2 3 1
``````
##### Sample Output 1 :
``````2
``````
##### Explanation Of Sample Input 1 :
``````Test case 1:
Given that we follow 1-based indexing, for the array {1, 2, 3, 2, 1}, the pairs satisfying the conditions of Reverse Pairs are
For i = 3, arr[i] = 3 and for j = 6, arr[j] = 1.
For i = 5, arr[i] = 3 and for j = 6, arr[j] = 1.
Hence there are two possible pairs.
``````
##### Sample Input 2 :
``````2
6
6 4 8 2 1 3
5
2 4 3 5 1
``````
##### Sample Output 2 :
``````6
3
``````
##### Explanation Of Sample Input 2 :
``````Test case 1:
Given that we follow 1-based indexing,The possible pairs satisfying the conditions of Reverse Pairs are (1, 4), (1, 5), (2, 5), (3, 4), (3, 5), (3, 6). Thus, the answer is 6.

Test case 2:
Given that we follow 1-based indexing, The possible pair of indices satisfying the above condition are (2, 5), (3, 5), (4, 5). Thus, the answer is 3.
``````  Auto Console