A work queue workList must be processed in order by two handlers. Each value in workList is a work type from 1 through m.
For work type t, the first time a handler processes that type, or whenever the handler's previous job was a different type, that handler pays longPrepTime[t]. If the handler's previous job was the same type, that handler pays shortPrepTime[t] instead.
Each job must be assigned to exactly one of the two handlers, and jobs must be processed in the order they appear. Return the minimum total preparation time.
Complete the function minPreparationTime in the editor below.
minPreparationTime has the following parameters:
int[] workList: the ordered work typesint[] longPrepTime: long preparation time for each work typeint[] shortPrepTime: short preparation time for each work type
Returns
int: the minimum total preparation time.
workList = [1, 2, 2] longPrepTime = [4, 5] shortPrepTime = [2, 3] return = 12
Assign work type 1 to the first handler, then assign both type-2 jobs to the second handler. The total cost is 4 + 5 + 3 = 12.
workList = [1, 1, 1] longPrepTime = [4] shortPrepTime = [2] return = 8
Use the same handler for all three jobs to pay one long preparation and two short preparations.
workList[i]identifies a work type between1andmlongPrepTimeandshortPrepTimecontain one entry per work type.- Jobs must be processed in order.
- Closest Version DateONSITE INTERVIEW · Seen Jul 2026
- Maximum Concurrent Processes (Bar Raiser Round)ONSITE INTERVIEW · Seen Jul 2026
- Maximum Product New RatingOA · Seen Jul 2026
- Permutation SorterOA · Seen Jul 2026
- Get Distinct Pairs (Also apply to AS intern)Seen Jul 2026
- Maximum Final ValueSeen Jul 2026
- Minimum Delivery Center InconvenienceOA · Seen Jun 2026
- Unfulfilled Customers by Inventory PriorityOA · Seen Jun 2026
public int minPreparationTime(int[] workList, int[] longPrepTime, int[] shortPrepTime) {
// write your code here
}