Round Robin Load Balancer
INTERN
Implement a prototype of a round-robin load-balancing algorithm.
There are n servers indexed from 1 to n , and m requests to be processed.
The i
Given n , arrival , and burstTime for each request, find the index of the server that executes it. If no server is available at the time, the request is dropped, and -1 is reported. If multiple requests arrive at the same time, the one with the smaller index is assigned first.
Function Description
Complete the function getServerIndex in the editor.
getServerIndex has the following parameter(s):
- int n : the number of servers
- int arrival[m] : the arrival time of requests
- int burstTime[m] : the burst time of requests
Returns
int[m] : the Index of the servers the requests are assigned to, or -1 if no server is available
Example 1 :
Input: n = 3, arrival = [2, 4, 1, 8, 9], burstTime = [7,
9, 2, 4, 5]
Output: [1, 2, 1, 3, 2]
Explanation:
Look carefully at the explaination image shown above ?. Answer is [1, 2, 1,
3, 2].
Constraints:
Get one-to-one training from Google Facebook engineers
Top-notch Professionals
Learn from Facebook and Google senior engineers interviewed 100+ candidates.
Most recent interview questions and system design topics gathered from aonecode alumnus.
One-to-one online classes. Get feedbacks from real interviewers.
Customized Private Class
Already a coding expert? - Advance straight to hard interview topics of your interest.
New to the ground? - Develop basic coding skills with your own designated mentor.
Days before interview? - Focus on most important problems in target company question bank.