Dsa
Queue
Easy
Two-Stage Assembly Line
An assembly line has two stages. Stage 1 takes S1 minutes, and Stage 2 takes S2 minutes. Only one item can be in a specific stage at a time. Items arrive at specific times and must pass through Stage 1 then Stage 2. An item cannot start Stage 2 until it finishes Stage 1 AND Stage 2 is empty. Given S1, S2, and a list of arrival times, calculate the time each item exits Stage 2.
Example:
Input: 2 3 0 1 5
Output: 5 8 11
Explanation:
- Item 1: Arrives 0. S1 finishes at 2. S2 finishes at 5.
- Item 2: Arrives 1. S1 starts at 2 (after Item 1), finishes at 4. S2 starts at 5 (after Item 1), finishes at 8.
- Item 3: Arrives 5. S1 starts at 5, finishes at 7. S2 starts at 8 (after Item 2), finishes at 11.
Key concepts
queuesimulationconcurrency
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