Compute Relative Player Ratings
Learn this problemProblem statement
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 each player's relative rating, which is derived from the sum of the absolute ratings of up to k players who have strictly 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]. In other words, among all players whose skill is strictly less than skills[i], take the k largest absolute ratings (or all of them if fewer than k exist) and sum them.
For example, if skills = [1, 2, 3, 4], ratings = [40, 30, 20, 10], and k = 2, then the relative ratings are [0, 40, 70, 70].
Given skills, ratings, and k, implement a function called getRelativeRatings that returns each player's relative rating.
Parameters:
skills(List[int]): An array of integers whereskills[i]represents the skill level of the i-th player.ratings(List[int]): An array of integers whereratings[i]represents the absolute rating of the i-th player.k(int): The maximum number of top ratings to consider for computing the relative rating.
Function
getRelativeRatings(skills: int[], ratings: int[], k: int) → long[]Examples
Example 1
skills = [1, 2, 3, 4]ratings = [40, 30, 20 ,10]k = 2return = [0, 40, 70, 70]For each player, sum the largest k = 2 absolute ratings among players with strictly lower skill.
- Player with skill 1: no player has lower skill, so relative rating =
0. - Player with skill 2: only skill 1 (rating 40) is lower, so relative rating =
40. - Player with skill 3: skills 1 and 2 (ratings 40 and 30) are lower; sum of top 2 =
70. - Player with skill 4: skills 1, 2, 3 (ratings 40, 30, 20) are lower; the top 2 are 40 and 30, summing to
70.
Hence the answer is [0, 40, 70, 70].
Example 2
skills = [1, 7, 5]ratings = [0, 0, 1]k = 1return = [0, 1, 0]
[0, 1, 0].Constraints
1 ≤ n ≤ 2 * 10^50 ≤ k ≤ n - 11 ≤ skills[i] ≤ 10^90 ≤ ratings[i] ≤ 10^9
More Amazon problems
- Resolve Task DependenciesONSITE INTERVIEW · Seen Jul 2026
- Shortest Distance on a Circular Bus RouteOA · Seen Jul 2026
- Longest Increasing Subsequence With Bounded Adjacent DifferenceONSITE INTERVIEW · Seen Jul 2026
- Search in a Rotated Sorted ArrayONSITE INTERVIEW · Seen Jul 2026
- Sliding Window MaximumONSITE INTERVIEW · Seen Jul 2026
- Merge IntervalsOA · Seen Jul 2026
- Sort Bug Report FrequenciesOA · Seen Jul 2026
- Drone Delivery RouteOA · Seen Jul 2026