Code RoomSignificant inversions
HardPrep Room Coding #1000

Significant inversions

CodingAlgorithms & data structuresSenior–Staff~30 min

Count the number of 'significant' inversions in an array: pairs of indices (i, j) with i < j such that nums[i] > 2 * nums[j]. The array has up to 10^5 elements and values may be negative and fit in 32-bit ints. An O(n^2) double loop is too slow; use a modified merge sort. Return the count.

Implement
count_significant_inversions(nums: list[int]) → int
Examples
in[[1,3,2,3,1]]out2
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 30 min
InputExpectedGot
[[1,3,2,3,1]]2not run yetsample