Dsa
Heap
Easy
The Efficient Factory
A factory has K identical assembly lines (workers). There are N tasks that must be processed in the exact order they arrive. Each task has a duration in minutes. A task is always assigned to the worker who becomes free earliest. If multiple workers are free at the same time, the task is assigned to the worker with the lowest ID (from 0 to K-1). Determine the time when all tasks are completed.
Example:
K=2 workers, N=3 tasks with durations [10, 2, 5].
- Task 0 (dur 10) assigned to Worker 0 (ends at 10).
- Task 1 (dur 2) assigned to Worker 1 (ends at 2).
- Task 2 (dur 5) assigned to Worker 1 (now ends at 7).
Result: 10 (the maximum of all workers' finish times).
Key concepts
heapgreedysimulation
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now