Problem · Array
Minimum Time to Process Requests
Learn this problemProblem statement
A system has n services numbered 1 to n, and m requests to be processed. The service where the i-th request is cached is denoted by cache[i].
Processing a request from cache takes 1 unit of time; otherwise, it takes 2 units. 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 requests by optimally allocating each request to a service.
Function
getMinTime(n: int, cache: int[]) → intComplete the function getMinTime in the editor with the following parameters:
int n: the number of services in the systemint cache[m]: the service in which the request is cached
Examples
Example 1
n = 3cache = [1, 1, 3, 1, 1]return = 3An optimal allocation:
- Assign
1st,2nd, and4threquests to service1:3time units. - Assign
3rdrequest to service3:1time unit. - Assign
5threquest to service2:2time units.
All requests can be processed in 3 time units.
More Citadel problems
- Minimum Changes for a Periodic PalindromeOA · Seen Jul 2026
- Minimum Image Processing CostOA · Seen Jul 2026
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Process SchedulingOA · Seen Mar 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Price CheckSeen Feb 2025
- Palindromic Substrings (LC 647 :)Seen Jan 2025