FastPrepAssign Partitions to the Least-Loaded Servers
Problems/Assign Partitions to the Least-Loaded Servers

Assign Partitions to the Least-Loaded Servers

Amazon logoAmazon● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in an Amazon new grad onsite interview. The report says to give each new partition to the server with the least load right now, then update that load. It does not give the function signature or a tie rule. Our version is about 95% the same as the reported question.

You operate several servers. Server i begins with load serverLoads[i]. A sequence of incoming partitions arrives in order, and partitionLoads[j] is the load added by partition j.

Assign each incoming partition to the server with the smallest current load. If several servers have the same smallest load, choose the server with the smallest index. Immediately add the partition's load to the chosen server before assigning the next partition.

Return an array where result j is the zero-based index of the server chosen for partition j.

Function

assignPartitions(serverLoads: long[], partitionLoads: int[]) → int[]

Examples

Example 1

serverLoads = [8,3,5]partitionLoads = [4,2,7]return = [1,2,1]

The first partition goes to server 1, producing loads [8,7,5]. The second goes to server 2, producing [8,7,7]. Servers 1 and 2 then tie, so the final partition goes to server 1.

Example 2

serverLoads = [0,0]partitionLoads = [1,1,1]return = [0,1,0]

The smaller server index breaks both load ties. After the first two assignments the loads are equal again, so the third partition returns to server 0.

Example 3

serverLoads = [2]partitionLoads = [5,3]return = [0,0]

With one server, every partition is assigned to index 0.

Constraints

  • 1 <= serverLoads.length <= 2 * 10^5.
  • 0 <= partitionLoads.length <= 2 * 10^5.
  • 0 <= serverLoads[i] <= 10^15.
  • 0 <= partitionLoads[j] <= 10^9.
  • The final load of every server fits in a signed 64-bit integer.

More Amazon Onsite Interview questions

  • Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Dungeon GameONSITE INTERVIEW · Seen Nov 2026
  • Integer BreakONSITE INTERVIEW · Seen Nov 2026
  • LFU CacheONSITE INTERVIEW · Seen Nov 2026
  • LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
  • First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Automation Pipeline, Part 3: Stage DurationPlaid · PHONE SCREENPlaid interview questions
  • Tennis Court SchedulingAtlassian · PHONE SCREEN · ONSITE INTERVIEWAtlassian interview questions
  • Latest Arrival Time for a ShuttleGoogle · ONSITE INTERVIEWGoogle interview questions
  • API Call Thread Pool ScheduleBaseten · ONSITE INTERVIEWBaseten interview questions
  • Minimum Workers with Job AssignmentsLyft · ONSITE INTERVIEWLyft interview questions
  • Cursor-Based Pagination Over Sorted LogsRoblox · ONSITE INTERVIEWRoblox interview questions
  • Issue and Reuse 16-Bit TokensMeta · ONSITE INTERVIEWMeta interview questions
  • Most Transactions Kept Without Going NegativeDocuSign · ONSITE INTERVIEWDocuSign interview questions
  • Weighted Server Load Balancer with TTLStripe · ONSITE INTERVIEWStripe interview questions
  • Movie Schedule for Maximum EnjoymentC3.ai · ONSITE INTERVIEWC3.ai interview questions

Interview reports that mention this question

  • Amazon New Grad SDE Onsite Interview Questions: 17 Experiences

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
See Amazon hiring insights
Saved
class Solution {
    public int[] assignPartitions(long[] serverLoads, int[] partitionLoads) {
      // Write your code here
    }
}
Checking account…