FastPrepFastPrep
Problem Brief

Compute Relative Player Ratings

NEW GRADOA

A newly launched game on the The Banana Inc gaming platform has introduced a distinctive player rating system that evaluates players based on both their skill levels and absolute ratings. The goal is to determine a player's relative rating, which is derived from the sum of the absolute ratings of up to k players who have lower skill levels than the player in question.

There are n players in the game, where each player i possesses:

  • A skill level represented by skills[i]
  • An absolute rating denoted as ratings[i]
  • The relative rating for each player i is calculated as the highest possible sum of the absolute ratings of at most k players who have a skill level strictly less than skills[i].

    For instance, consider the following input:

    [0, 40, 70, 70]

    The Banana Inc now wants you to implement a function called computeRelativeRatings.

    What parameters does this function have?

  • skills(List[int]) - An array of intergers where skills[i] represents the skill level of the i-th player in the game we carefully designed above~~
  • ratings (List[int]): An array of integers where ratings[i] represents the absolute rating of the i-th player.
  • k (int): An integer representing the maximum number of top ratings to consider for computing the relative rating.
  • Many thanks to moshema!

    1Example 1

    Input
    skills = [1, 2, 3, 4], ratings = [40, 30, 20 ,10], k = 2
    Output
    [0, 40, 70, 70]
    Explanation
    Added this example on 02-28-2025 for your testing convenience. You can find the exaplanation from the problem prompt~~~

    2Example 2

    Input
    skills = [1, 7, 5], ratings = [0, 0, 1], k = 1
    Output
    [0, 1, 0]
    Explanation
    Example 2 illustration
    With k = 1, choose one maximum skill level less than the current one. No skill level is less than 1. For skill lelvel 7, skill level 5 and 1 are lower but only 5 has a relative rating > 0. The only skill level less is 1 with a rating of 0. Hence the answer is [0, 1, 0].

    Constraints

    Limits and guarantees your solution can rely on.

  • 1 ≤ n ≤ 2 * 10^5
  • 0 ≤ k ≤ n - 1
  • 1 ≤ skills[i] ≤ 10^9
  • 1 ≤ ratings[i] ≤ 10^9
  • public long[] getRelativeRatings(int[] skills, int[] ratings, int k) {
      // write your code here
    }
    
    Input

    skills

    [1, 2, 3, 4]

    ratings

    [40, 30, 20 ,10]

    k

    2

    Output

    [0, 40, 70, 70]

    Sign in to submit your solution.