BackmediumArrays PhonePe

Reverse Index Pairs Count Solution

Problem Statement

You are given an array of integers `arr` of length `n`. Find the maximum number of pairs that can be formed such that the index of the first element is greater than the index of the second element and the value of the first element is less than the value of the second element.

Example 1
Input
[4, 3, 2, 1]
Output
6

Explanation: All possible pairs are (1,0), (2,0), (2,1), (3,0), (3,1), (3,2) with index of first element greater than index of second element.

Constraints

  • 1 <= n <= 10^5
  • -10^9 <= arr[i] <= 10^9
  • n is the number of elements in the array
  • All elements in the array are distinct
Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free