All problems
Top-K Recommendations
Problem
Rank unseen items for a user.
scores is a list of predicted scores per item and rated lists the item indices the user has already rated. Return the k unseen item indices with the highest scores, breaking ties by smaller index, as a list.
Hint
Filter out rated items first, then sort by descending score.
Test cases
case 1
in: [[0.1,0.9,0.5,0.7],[0],2]
expected: [1,3]
case 2
in: [[1,2,3],[],3]
expected: [2,1,0]
case 3
in: [[1,2],[0,1],2]
expected: []
case 4
in: [[5,5,5],[],2]
expected: [0,1]
Starter codePython
def top_k_items(scores, rated, k):
# Your code here
pass4 test cases · run your code against them in the editor