Code Question 1
Amazon Shopping is running a reward collection event for its customers. There are n customers and the ith customer has collected initialRewards[i] points so far.
One final tournament is to take place where the winner will be awarded n points, the runner-up will awarded n - 1 points, the third place will get n - 2 points, and so on until the last place gets 1 point.
Given an integer array initialRewards of length n, representing the initial reward points of the customers initially before the final tournament.
Find the number of customers such that, if the ith customer wins the final tournament (i.e., they get the n points), they would have the highest total reward points.
Note: The total points for a customer is calculated as the sum of their initialRewards points and the points they would receive from the tournament, with the winner receiving n points.
Example
n = 3
initialRewards = [1, 3, 4]
Let'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 = 1 + 3 = 4, but this is not the highest possible points among all customers.
- If the 2nd customer wins the final tournament: Their total = 3 + 3 = 6.
- If the 3rd customer wins the final tournament: Their total = 4 + 3 = 7.
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.
import java.io.*;
class Result {
public static int countPossibleWinners(List<Integer> initialRewards) {
//Write your code here
}
}