Skip to main content
All Questions

Assign stations to two handlers to minimize the total processing time.

Unlock detailed company stats for this questionUpgrade

You are given n stations that must be processed in order from 0 to n-1. Station i has a workflow type workflow[i] (1-indexed type id). There are two handlers, and each station must be processed by exactly one handler. For a station of type t, if a handler processes it immediately after processing another station of the same type t, it takes shortPrep[t] time; otherwise (different type, or the handler's first ever station) it takes longPrep[t]. Assign each station to one of the two handlers to minimize the total processing time, and return that minimum total time.

Example: workflow = [1, 2, 1, 2], longPrep = [10, 6, 5], shortPrep = [4, 2, 4] gives 22. Handler A: station 0 (type 1) takes 10; Handler B: station 1 (type 2) takes 6; Handler A: station 2 (type 1) takes short 4; Handler B: station 3 (type 2) takes short 2. Total = 10 + 6 + 4 + 2 = 22.

Community answers

No answers contributed by the community yet.

Related courses

Course

Software Engineering Interview Prep

Land your dream software engineering role at Google, Amazon, Microsoft, Meta, Apple, and other top companies. Learn from mock interviews, frameworks, and advice from senior candidates—practice data structures, algorithms, system design, people management, behavioral interviews, and more.

Course

System Design Interviews

Learn how to answer the latest system design questions across product, infrastructure, and AI domains. Features in-depth video examples, written breakdowns, and helpful reference patterns. Watch senior engineers and managers answer these questions in mock interview videos.