Tap here to switch tabs
Problem
Submissions

Problem: Reverse Pairs

Reverse Pairs asks you to count array index pairs where the first position comes earlier and its value is more than twice the later value, including negative numbers.

Statement

You are given an integer array, nums. Your task is to count how many reverse pairs exist in the array and return the total number of such pairs.

A reverse pair is defined as a pair of indexes (i,j)(i, j) such that:

  • 0≤i<j<0 \leq i \lt j \lt nums.length, and

  • nums[i] >2×\gt 2 \times nums[j].

Constraints:

  • 1≤1 \leq nums.length ≤5×104\leq 5 \times 10^4

  • −231≤-2^{31} \leq nums[i] ≤231−1\leq 2^{31} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Reverse Pairs

Reverse Pairs asks you to count array index pairs where the first position comes earlier and its value is more than twice the later value, including negative numbers.

Statement

You are given an integer array, nums. Your task is to count how many reverse pairs exist in the array and return the total number of such pairs.

A reverse pair is defined as a pair of indexes (i,j)(i, j) such that:

  • 0≤i<j<0 \leq i \lt j \lt nums.length, and

  • nums[i] >2×\gt 2 \times nums[j].

Constraints:

  • 1≤1 \leq nums.length ≤5×104\leq 5 \times 10^4

  • −231≤-2^{31} \leq nums[i] ≤231−1\leq 2^{31} - 1