Code Room
CodingHard
Question
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]) → intExamples
in
[[1,3,2,3,1]]out2What 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.
Learn the concepts
Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.
Run or narrate your approach, then ask the coach.