Compute the total cost of allocating machine instances to M customers.
Unlock detailed company stats for this questionUpgrade
Given an array with the number of instances available for each machine type, M customers arrive one by one. Each customer is allocated an instance from the machine type with the most available instances. The customer's cost is (maximum instances before allocation) + (minimum non-zero instances currently present). After allocation that machine's count drops by 1. Continue until all customers are processed or instances run out, and return the total cost. Example: instances = [1, 3, 2, 4]: customer 1 sees max=4, min=1, cost=5, and the array becomes [1, 3, 2, 3].
Community answers
No answers contributed by the community yet.
Related courses

Course

Course
Course
