This is one of the question which is asked in Code with Cisco online round
There are n services numbered from 1 to n in a system, and there are m requests to be processed. The service in which the ith request is cached is denoted by cachefi], for all 1 ≤ i ≤ m. For any request, if the request is processed from a cache, then it takes 1 unit of time. Otherwise, it takes 2 units of time.
Different services can process different requests simultaneously, but one service can only process one request at a time. Find the minimum time to process all the requests by allocating each request to a service.
Example
It is given that n = 3, m = 5, and cache = [1, 1, 3, 1, 1].
If the 1st, 2nd, and 4th requests are assigned to the 1st service, it will take 1 unit of time each, or 3 units of time to process them in total.
Assign the 3rd request to the 2nd service and the 5th request to the 3rd service. It takes 1 and 2 units of time to complete them, respectively.
Therefore, all requests are processed in 3 units of time.

Comments (3)