Developers at Amazon have their applications deployed on n servers. Initially, the ith server has an id server[i] and can handle server[i] requests at a time.
For maintenance purposes, some servers are replaced periodically. On a jth day, all the servers with id equal to replaced[j] are replaced with servers with id newId[j] that can serve newId[j] requests. The total number of requests served on a jth day is the sum of the ids of the servers that the application is running on.
Given server, replaced, and newId, find the total number of requests served by the servers each day.
Note: The indices i and j are assumed to follow 1-based indexing.
Complete the function getTotalRequests in the editor.
getTotalRequests takes the following arguments:
- 1.
int server[n]: the initial server ids - 2.
int replaced[n]: the ids of the servers to replace - 3.
int newId[n]: the new ids of the replaced servers
Returns
int[]: an array of integers representing the total number of requests served each day
server = [20, 10] replaced = [10, 20] newId = [20, 1] return = [40, 2]

Day 1: The servers are [20, 10]. Server with id 10 is replaced by a server with id 20. New servers are [20, 20]. Total requests = 20 + 20 = 40.
Day 2: The servers are [20, 20]. Server with id 20 is replaced by a server with id 1. New servers are [1, 1]. Total requests = 1 + 1 = 2.
Hence the answer is [40, 2].
server = [3, 3] replaced = [3, 1] newId = [1, 5] return = [2, 10]
server = [2, 5, 2] replaced = [2, 5, 3] newId = [3, 1, 5] return = [11, 7, 11]
1 ≤ n ≤ 10^51 ≤ server[i], replaced[i], newId[i] < 10^4server,replaced, andnewIdeach have exactlynelements.
- Get the Fewest Moves (~Operations~)~Seen Jun 2026
- Create Array Generator ServiceSeen Jun 2026
- Minimum Merge ConflictsOA · Seen Jun 2026
- Get Minimum AmountOA · Seen Jun 2026
- Drone Delivery RouteOA · Seen Jun 2026
- Minimum Operations to Make Array ValidOA · Seen Jun 2026
- Sort Bug Report FrequenciesOA · Seen Jun 2026
- Maximum Equal Parts for PrefixesOA · Seen Jun 2026
public int[] getTotalRequests(int[] server, int[] replaced, int[] newId) {
// write your code here
}