A can finish a job in 6 days and B in 12 days. If they work on alternate days, starting with A, in how many days will the job be finished?
8 days. With 12 units of work, A does 2 units a day and B 1. Every 2-day cycle does 3 units, so 4 cycles (8 days) finish exactly 12 units.
Explain it simply
When people work on alternate days, bundle one full round (A's day plus B's day) into a cycle. Count how many full cycles fit, then handle the leftover day by day. The leftover part decides whether the faster or the slower person finishes the job, so it matters who starts.
Example
Question: A takes 6 days, B 12 days. They alternate, A first.
- Total work = LCM(6, 12) = 12 units. A = 2/day, B = 1/day.
- One 2-day cycle = 3 units.
- 12 / 3 = 4 full cycles = 8 days, no leftover.
Now a case with leftover: A 6 days, B 9 days, alternating, A first. Total = 18 units, A = 3/day, B = 2/day, cycle = 5 units in 2 days. After 3 cycles (6 days) 15 units are done; day 7 is A's turn and A does the remaining 3. Answer 7 days.
function days(a, b, total) {
let done = 0, d = 0;
while (done < total) { done += d % 2 === 0 ? a : b; d++; }
return d;
}
console.log(days(2, 1, 12)); // Output: 8
console.log(days(3, 2, 18)); // Output: 7What to say in the interview
"I group one A-day and one B-day as a cycle doing 3 of the 12 units. Four cycles finish exactly, so 8 days. If there's a remainder I complete it day by day, remembering whose turn it is."
Common mistakes
- Using the together rate (4 days) as if they worked at the same time.
- Getting the leftover day wrong by forgetting who works next.