Skip to content
DeepForgeby svx
All problems
HardNLPnlp-250

Rerank Inversion Count

Problem

Measure how much a cross-encoder changed an original ranking by counting discordant pairs: pairs of documents that appear in both rankings but in opposite order.

Documents missing from either ranking are ignored, and duplicates in original keep their first position. Return the number of discordant pairs.

Hint

Map original positions, filter the reranked list to known documents, then count inversions in that sequence.

Test cases

case 1
in: [["a","b","c"],["c","b","a"]]
expected: 3
case 2
in: [["a","b","c"],["a","b","c"]]
expected: 0
case 3
in: [["a","b","c"],["c","x","a"]]
expected: 1
case 4
in: [[],["a"]]
expected: 0
case 5
in: [["a","b","c","d"],["b","d","a","c"]]
expected: 3
Starter codePython
def rerank_inversion_count(original, reranked):
    # Your code here
    pass

5 test cases · run your code against them in the editor