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 i
th request is cached is denoted by cache[i]
, 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.
Function Description
Complete the function getMinTime
in the editor.
getMinTime
has the following parameters:
int n
: the number of services in the systemint cache[m]
: the service in which the request is cached
Returns
int
: the minimum time required to process all requests
Example 1:
Input: n = 3, cache = [1, 1, 3, 1, 1]
Output: 3
Explanation: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.
Unknown for now ππ

input:
output: