Problem Statement:
There are n products in an Amazon catalogue, where the category of the ith product is represented by the array catalogue.
The catalogue will be called valid if the number of distinct product categories in it is at most k. If the catalogue is not valid initially, then make it valid by removing some products from the catalogue.
Given n products and an array catalogue, find the minimum number of products to remove from the catalogue to make it valid.
Example:
n = 4, catalogue = [3, 3, 5, 7], k = 1
Number of distinct product categories is 3 ([3, 5, 7]). To make the distinct categories at most 1, we can remove the elements 5 and 7. The remaining catalogue is [3, 3]. The number of removed products is 2.
(Note: Removing all 3s would mean removing 2 products and leaving [5, 7] which still has 2 categories, requiring more removals. Minimum removals is 2).
There are n players where the ith player has a skill level of skill[i] and an absolute rating of rating[i]. The relative rating of the ith player is defined as the maximum possible sum of ratings of at most k players with a skill level strictly less than skill[i]. Given skill, rating, and k, find each player's relative rating.
Example:
n = 4, skill = [4, 5, 9, 7], rating = [1, 2, 3, 4], k = 2
Output: [0, 1, 6, 3]