Minimum Preparation Time for Two Handlers
Learn this problemProblem statement
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.
Function
minPreparationTime(workList: int[], longPrepTime: int[], shortPrepTime: int[]) → intComplete 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.
Examples
Example 1
workList = [1, 2, 2]longPrepTime = [4, 5]shortPrepTime = [2, 3]return = 12Assign 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.
Example 2
workList = [1, 1, 1]longPrepTime = [4]shortPrepTime = [2]return = 8Use the same handler for all three jobs to pay one long preparation and two short preparations.
Constraints
workList[i]identifies a work type between1andmlongPrepTimeandshortPrepTimecontain one entry per work type.- Jobs must be processed in order.