Your question is Load Balancing Algorithm. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Cruise can distribute autonomous-vehicle compute requests across a fixed pool of servers. Each request has a known processing duration and must be assigned immediately without moving previously assigned work. Implement a greedy load balancer that assigns every request to the server with the smallest current total load.
Implement load_balance(server_loads, requests), where server_loads is an array of nonnegative integers representing each server's existing workload, and requests is an array of nonnegative integers representing processing durations in arrival order. Return an array assignments where assignments[i] is the zero-based server index selected for requests[i].
If multiple servers have the same minimum load, choose the server with the smallest index. After assigning a request, add its duration to that server's load before processing the next request.
def load_balance(server_loads, requests):