Design Gurus Logo
Reverse Pairs (hard)

Problem Statement

Given an array of integers nums, return the count of reverse pairs in the array.

A reverse pairis a pair (i, j) where:

  • 0 <= i < j < nums.length and
  • nums[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).
  • Example 2:

    • Input: nums = [4, 1, 2]
    • Expected Output: 1
    • Justification: There is only one reverse pair (0, 1) since 4 > 2 * 1.
  • 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).

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory