Grokking Google Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Reverse Pairs (hard)
On this page

Problem Statement

Examples

Try it yourself

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

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

On this page

Problem Statement

Examples

Try it yourself