Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-148

Reciprocal Rank Fusion

Problem

Combine ranked lists with reciprocal rank fusion. Each document receives the sum over lists of 1 / (k + rank), where rank starts at 1.

Return document ids sorted by descending fused score with alphabetical tie-breaking.

Hint

The same document can appear in several lists and accumulates each contribution.

Test cases

case 1
in: [[["a","b","c"],["b","c","a"]],60]
expected: ["b","a","c"]
case 2
in: [[["a"],["a"]],1]
expected: ["a"]
case 3
in: [[],60]
expected: []
case 4
in: [[["x","y"],[]],60]
expected: ["x","y"]
Starter codePython
def reciprocal_rank_fusion(rankings, k=60):
    # Your code here
    pass

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