Count Possible Winners (All About Rewards :)
Learn this problemProblem statement
SDE II
Amazon Shopping is running a reward collection event for its customers.
There are n customers and the i-th customer has collected initialRewards[i] points so far.
One final tournament is to take place where:
Given an integer array initialRewards of length n, representing the initial reward points of the customers before the final tournament:
Find the number of customers i (1 ≤ i ≤ n) such that, if the i-th customer wins the final tournament, they would have the highest total points.
Note -
The total points = initialRewards[i] + n (if they win). Other customers also get points in the tournament depending on their ranks (from n - 1 to 1). You must check if the i-th customer, upon winning, ends up with the highest total score, regardless of how others place.
Function
countPossibleWinners(initialRewards: int[], n: int) → intExamples
Example 1
initialRewards = [1, 3, 4]n = 3return = 2Let's analyze for each customer if they win the final tournament, would they have the highest total points or not:
If the 1st customer wins the final tournament, their total points would be:
1 + 3 = 4, but this is not the highest possible points in this case.For example, if the 3rd customer with an initial reward of
4comes 2nd, then they would achieve a total of:4 + 2 = 6points which is the higher than 1st customer points.If the 2nd customer wins the final tournament, their total points would be:
3 + 3 = 6, and this is the highest total points in this case.Even if the 3rd customer with an initial reward of
4comes 2nd, then they would achieve a total of:4 + 2 = 6points which is not greater than 2nd customer points.If the 3rd customer wins the final tournament, their total points would be:
4 + 3 = 7, and this is the highest total points, as there are no other customers that can achieve the total point of7in this case.
Thus, the customers 2 and 3 are the ones such that, if they win the final tournament, they would have the highest total points.
Hence the answer is 2.
Example 2
initialRewards = [5, 7, 9, 11]n = 4return = 1Only the 4th customer is the one such that, if they win the final tournament, they would have the highest total points.
Example 3
initialRewards = [8, 10, 9]n = 3return = 2Only the 2nd and the 3rd customers are the ones such that, if they win the final tournament, they would have the highest total points.
If the 2nd customer wins the final tournament, their total points would be:
10 + 3 = 13, and this is the highest total points, as there are no other customers that can achieve the total point of13in this case.If the 3rd customer wins the final tournament, their total points would be:
9 + 3 = 12, and this is the highest total points in this case.Even if the 2nd customer with an initial reward of
10comes 2nd, then they would achieve a total of:10 + 2 = 12points which is not greater than 2nd customer points.
Constraints
1 ≤ n ≤ 10^50 ≤ initialRewards[i] ≤ 10^5- Complete constraints added on 06-18-2025
More Amazon problems
- Secure Maximum DeliveriesOA · Seen Jul 2026
- Find Median from Data StreamONSITE INTERVIEW · Seen Jul 2026
- Handwritten SigmoidPHONE SCREEN · Seen Jul 2026
- Handwritten SoftmaxPHONE SCREEN · Seen Jul 2026
- Koko Eating BananasONSITE INTERVIEW · Seen Jul 2026
- Loyal Customers Across Two DaysONSITE INTERVIEW · Seen Jul 2026
- Maximum System Memory CapacityOA · Seen Jul 2026
- Package Delivery SystemOA · Seen Jul 2026