Reverse Pair Count Problem

Reverse Pair Count Problem — ExecCode Hard DSA Practice

Solve the Reverse Pair Count problem on ExecCode. Free online hard DSA practice in Two Pointers. Write and run code in Java, C++, Python — no signup required to run.

Problem description

A reverse pair is (i, j) with i 2 * nums[j]. This is stricter than a classic inversion, so a plain inversion counter is wrong. Return the number of reverse pairs. You are given: nums — integer array, values may be negative Return integer count. Pairs are unordered in value but ordered in indices: i must be left of j.

Examples

Input {'nums': [1, 3, 2, 3, 1]}; Output 2. Input {'nums': [2, 4, 3, 5, 1]}; Output 3. Input {'nums': [5, 4, 3, 2, 1]}; Output 4

Constraints

Negative numbers matter: doubling preserves sign Overflow: compare using 64-bit thinking (nums[i] > 2*nums[j])

Practice Reverse Pair Count free on ExecCode. Browse DSA problems, topic map, and placement guides.