Minimum Preparation Time for Two Handlers
Updated
Problem statement
You are given a work queue workList. Two handlers share the jobs, and the jobs must be done in the order they appear. Each value in workList is a work type from 1 through m.
Each job goes to exactly one of the two handlers. Before a handler does a job of type t, it pays a preparation time:
- If the handler's previous job was the same type, it pays
shortPrepTime[t]. - Otherwise it pays
longPrepTime[t]. This covers the first time the handler does that type and any job that comes right after a different type.
Return the minimum total preparation time.
Write minPreparationTime, which gets three arguments:
int[] workList: the ordered work typesint[] longPrepTime: long preparation time for each work typeint[] shortPrepTime: short preparation time for each work type
minPreparationTime returns an int: the minimum total preparation time.
Function
minPreparationTime(workList: int[], longPrepTime: int[], shortPrepTime: int[]) → intExamples
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. Its first job pays the long time, and the next two jobs pay the short time. The total is eight.
Constraints
workList[i]is a work type between1andmlongPrepTimeandshortPrepTimecontain one entry per work type.- Jobs must be processed in order.
More Amazon Online Assessment questions
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize Shipment Order by Sorting One WindowOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
- Two SumOA · PHONE SCREEN · Seen Nov 2026
Similar questions at other companies
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- 0/1 KnapsackConfluent · OAConfluent interview questions
- Minimum Cost to Tile a Strip with Widths 1, 2, and 3Infosys · OAInfosys interview questions
- Maximum Escape Game ScoreMicrosoft · OAMicrosoft interview questions
- Maximum Subarray SumStraive · OA
- Longest Increasing Price SubsequenceOpenAI · OAOpenAI interview questions
- Lowest-Cost Shirt Color ScheduleElevenLabs · OAElevenLabs interview questions
- Maximum Game Board ScoreJP Morgan Chase · OAJP Morgan Chase interview questions
- API Bandwidth AllocationArista Networks · OAArista Networks interview questions
- Maximum Points by Deleting ElementsIBM · OAIBM interview questions