Click4Ai

531.

Medium

Diversity in Recommendations

In recommender systems, diversity is a crucial aspect to ensure that users are exposed to a variety of items. One way to measure diversity is by calculating the coverage of a set of recommended items. Coverage is defined as the ratio of unique items in the recommended set to the total number of unique items in the entire catalog.

**Example:** Suppose we have a catalog of 100 movies and a user's rating history. We want to recommend 10 movies to the user. If the recommended set contains 5 unique movies, the coverage would be 5/100 = 0.05.

**Constraints:** The input is a 2D array where each row represents a user's rating history, and each column represents a movie's ID. The output should be the coverage of the recommended set.

Test Cases

Test Case 1
Input: [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]
Expected: 0.2
Test Case 2
Input: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Expected: 1.0
+ 3 hidden test cases