FastPrepFastPrep
Problem Brief

Rank Movies by Similarity Score (FrontEnd :)

INTERNOA

In this problem, we will implement a solution where given a single source movie that a user has liked in the past, we return groups of target movies.

Given a source movie, you have access to a similarity score of the source movie with all target movies. You also have the groups of target movies that you need to rank. Using this information, you can generate a score for each group given the source movie by taking the top k similar movies in each group, and using them to compute a score for the group using the following formula:

∑_(i=1)^k score_i.

For example, if the similarity scores for the target movies are [0.3, 0.2, 0.1, 0.4, 0.5], where the array index is the id of the movie; and a group has movies [1, 2, 4], the corresponding scores are [0.2, 0.1, 0.5]. For a value of k = 2, the score of this collection would be 0.5 + 0.2 = 0.7.

1Example 1

Input
similarityScores = [0.3, 0.2, 0.1, 0.4, 0.5], movieGroups = [[1, 2, 4], [0, 3, 4]], k = 2
Output
[0.7, 0.9]
Explanation

For the first group [1, 2, 4], the top 2 similarity scores are [0.5, 0.2], so the score is 0.5 + 0.2 = 0.7.

For the second group [0, 3, 4], the top 2 similarity scores are [0.5, 0.4], so the score is 0.5 + 0.4 = 0.9.

public double[] rankMoviesBySimilarityScore(double[] similarityScores, int[][] movieGroups, int k) {
  // write your code here
}
Input

similarityScores

[0.3, 0.2, 0.1, 0.4, 0.5]

movieGroups

[[1, 2, 4], [0, 3, 4]]

k

2

Output

[0.7, 0.9]

Sign in to submit your solution.