Reverse pairs

Given an array of integers A, we call (i, j) an important reverse pair if i < j and A[i] > 2*A[j].

Return the number of important reverse pairs in the given array A.



Input Format

The only argument given is the integer array A.

Output Format

Return the number of important reverse pairs in the given array A.

Constraints

1 <= length of the array <= 100000
1 <= A[i] <= 10^9 

For Example

Input 1:
    A = [1, 3, 2, 3, 1]
Output 1:
    2

Input 2:
    A = [2, 4, 3, 5, 1]
Output 2:
    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 Reverse pairs on Interview Code Editor
Sign Up
to access hints and editorial solutions for Reverse pairs

Discussion


Loading...
Click here to start solving coding interview questions