FastPrepGet Total Requests
Problems/Get Total Requests

Get Total Requests

Amazon logoAmazon● EasyFULLTIMEOA

Updated Sep 2026

QuestionFunctionExamplesConstraints

Problem statement

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.

Function

getTotalRequests(server: int[], replaced: int[], newId: int[]) → int[]

Complete the function getTotalRequests in the editor.

getTotalRequests takes the following arguments:

  1. 1. int server[n]: the initial server ids
  2. 2. int replaced[n]: the ids of the servers to replace
  3. 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

Examples

Example 1

server = [20, 10]replaced = [10, 20]newId = [20, 1]return = [40, 2]
Example 1 illustration

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].

Example 2

server = [3, 3]replaced = [3, 1]newId = [1, 5]return = [2, 10]

After the first day, the servers are [1, 1]. After the second day, the servers are [5, 5] :)

Example 3

server = [2, 5, 2]replaced = [2, 5, 3]newId = [3, 1, 5]return = [11, 7, 11]

After the first day, the servers are [3, 5, 3].) After the second day, the servers are [3, 1, 3] :) After the third day,the servers are [5, 1, 5] :)

Constraints

  • 1 ≤ n ≤ 10^5
  • 1 ≤ server[i], replaced[i], newId[i] < 10^4
  • server, replaced, and newId each have exactly n elements.

More Amazon interview questions

  • Add Course Batches All or NothingONSITE INTERVIEW · Seen Dec 2026
  • Priority Ad Rotation with Show LimitsONSITE INTERVIEW · Seen Dec 2026
  • Next Greater Element IONSITE INTERVIEW · Seen Dec 2026
  • Count Connected ComponentsPHONE SCREEN · Seen Dec 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Merge Accounts by Shared AttributePHONE SCREEN · Seen Dec 2026
  • Merge IntervalsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026
  • Minimum Grid InconvenienceOA · Seen Dec 2026
  • Optimal Account BalancingONSITE INTERVIEW · Seen Dec 2026
  • Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Dec 2026

Similar questions at other companies

  • Macaron Order with Set DiscountsShopify · OAShopify interview questions
  • Basic Item DiscountsPalantir · OAPalantir interview questions
  • Calculate Portfolio Rebalancing DeltasAkuna Capital · OAAkuna Capital interview questions
  • Filter Transaction Logs and Calculate Reliability MetricsStripe · OAStripe interview questions
  • Balloon Color PairsInstacart · OAInstacart interview questions
  • Command Frequency CounterUber · OAUber interview questions
  • Cargo Port Ship StopsNutanix · OANutanix interview questions
  • Bank Accounts with Balance HistoryMeta · OAMeta interview questions
  • Parcel Attribute Store with TTLAirbnb · OAAirbnb interview questions
  • Process Banking OperationsVercel · OA

Interview reports that mention this question

  • Amazon Full-Time OA Problems, Recent Reports (Part 4 of 5)

Amazon interview experiences

  • Amazon Experienced SDE Onsite Questions: 1 Experience
  • Amazon SDE Onsite Interview Questions: 9 Experiences
  • Amazon SDE II and L5 FDE Interview Questions: 4 Experiences
  • Amazon Full-Time OA Problems, Earlier Reports (Part 5 of 5)
  • Amazon New Grad OA Problems: Every Task We Have (Part 3 of 5)
See Amazon hiring insights
Saved
class Solution {
    public int[] getTotalRequests(int[] server, int[] replaced, int[] newId) {
      // write your code here
    }

}
Checking account…