Back to course home
0% completed
Vote For New Content
Reverse Pairs (hard)
Problem Statement
Given an array of integers nums
, return the count of reverse pairs
in the array.
A reverse pair
is a pair (i, j)
where:
0 <= i < j < nums.length
andnums[i] > 2 * nums[j]
.
Examples
-
Example 1:
- Input:
nums = [4, 3, 4, 1]
- Expected Output:
3
- Justification: The three reverse pairs are
(0, 3)
,(1, 3)
and(2, 3)
.
- Input:
-
Example 2:
- Input:
nums = [4, 1, 2]
- Expected Output:
1
- Justification: There is only one reverse pair
(0, 1)
since4 > 2 * 1
.
- Input:
-
Example 3:
- Input:
nums = [6,5,4,3,2,1]
- Expected Output:
6
- Justification: The siz reverse pairs are
(0, 4)
,(0, 5)
,(1, 4)
,(1, 5)
,(2, 5)
and(3, 5)
.
- Input:
Try it yourself
Try solving this question here:
Python3
Python3
. . . .
.....
.....
.....
Like the course? Get enrolled and start learning!
On this page
Problem Statement
Examples
Try it yourself