Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-271

Weighted Answer Aggregation

Problem

Aggregate answers by total confidence weight. Sum weights per answer, then return [winner, winning_weight] for the largest total.

Ties break alphabetically, and an empty input returns ['', 0.0].

Hint

Use sorted keys and keep the first strict maximum.

Test cases

case 1
in: [["a","b","a"],[1,2,2.5]]
expected: ["a",3.5]
case 2
in: [[],[]]
expected: ["",0]
case 3
in: [["a","b"],[1,1]]
expected: ["a",1]
case 4
in: [["x","x","y"],[2,3,4]]
expected: ["x",5]
case 5
in: [["b","a","c"],[0.5,0.5,0.5]]
expected: ["a",0.5]
Starter codePython
def weighted_answer_aggregation(answers, weights):
    # Your code here
    pass

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