Count Possible Winners (All About Rewards :)
Updated
Problem 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:
- The champion earns n additional points
- The second place earns n - 1 points
- The third place earns n - 2 points
- … and the last place earns 1 point
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 interview questions
- Get Smallest Base SegmentOA · Seen Nov 2026
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- 3SumPHONE SCREEN · Seen Nov 2026
- Circular Primes Below a LimitPHONE SCREEN · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Capping Portfolio WeightsCapstone Investment Advisors · OA
- Count Servers With No Requests in a Time WindowIBM · OAIBM interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Largest Team Where Every Pair OverlapsWalmart · OAWalmart interview questions
- Maximum Distinct Values After Unit AdjustmentsBirla Pivot · OA
- Minimum Meeting RoomsJP Morgan Chase · OAJP Morgan Chase interview questions
- Minimize Task Resource ConsumptionNVIDIA · OANVIDIA interview questions
- Maximize Revenue from Decreasing InventoryChubb · OAChubb interview questions
- Macaron Order PriceOpenAI · OAOpenAI interview questions
- Earliest Meeting Time for All EmployeesCapital One · OACapital One interview questions
Amazon interview experiences
- Amazon SWE OA with AI Coding: 1 Experience
- Amazon SWE Intern Phone Screen Interview Experience: 1 Experience
- Amazon New Grad SDE I OA and Virtual Onsite: 1 Experience
- Amazon BIE Intern SQL and Interview Questions: 17 Experiences
- Amazon Experienced SWE AI-Assisted Debugging OA: 1 Experience
- Amazon SDE II (L5) Interview Questions: 5 Experiences