TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Catalog Coverage

Recommender SystemsMetrics & Evaluation
Easy

Catalog coverage measures how much of an item catalog appears in at least one recommendation list.

coverage⁡=∣R∣N\operatorname{coverage} = \frac{|R|}{N}coverage=N∣R∣​

Here, R is the set of unique recommended item IDs and N is n_items, the total catalog size. Return 0.0 when n_items is zero. Otherwise return the coverage as a float.

Loading visualization...

Examples

Input: recommendations = [[1, 2, 3], [2, 3, 4], [4, 5, 6]], n_items = 10

Output: 0.6

Explanation: Six unique items appear across a catalog of ten items.

Input: recommendations = [[1, 2], [1, 2], [1, 2]], n_items = 5

Output: 0.4

Hint 1

Use one set for items from every recommendation list.

Hint 2

Update the set with each list before dividing its size by n_items.

Requirements

  • Collect unique item IDs across all recommendation lists.
  • Divide the unique count by n_items.
  • Return 0.0 when n_items is zero.

Constraints

  • Recommendation lists contain integer item IDs.
  • n_items is nonnegative.
  • Recommended IDs belong to the catalog.
  • Time limit: 300 ms.
Try Similar Problems
Novelty ScoreTop K RecommendationsPopularity RankingHit Rate At KNdcg

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.
PrevNext

Catalog Coverage

Recommender SystemsMetrics & Evaluation
Easy

Catalog coverage measures how much of an item catalog appears in at least one recommendation list.

coverage⁡=∣R∣N\operatorname{coverage} = \frac{|R|}{N}coverage=N∣R∣​

Here, R is the set of unique recommended item IDs and N is n_items, the total catalog size. Return 0.0 when n_items is zero. Otherwise return the coverage as a float.

Loading visualization...

Examples

Input: recommendations = [[1, 2, 3], [2, 3, 4], [4, 5, 6]], n_items = 10

Output: 0.6

Explanation: Six unique items appear across a catalog of ten items.

Input: recommendations = [[1, 2], [1, 2], [1, 2]], n_items = 5

Output: 0.4

Hint 1

Use one set for items from every recommendation list.

Hint 2

Update the set with each list before dividing its size by n_items.

Requirements

  • Collect unique item IDs across all recommendation lists.
  • Divide the unique count by n_items.
  • Return 0.0 when n_items is zero.

Constraints

  • Recommendation lists contain integer item IDs.
  • n_items is nonnegative.
  • Recommended IDs belong to the catalog.
  • Time limit: 300 ms.
Try Similar Problems
Novelty ScoreTop K RecommendationsPopularity RankingHit Rate At KNdcg

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: number

You must run your code first.