Pipes A and B can fill a tank in 20 and 30 minutes. Both are opened, and after 5 minutes B is closed. How much longer does A take to fill the tank?
11 minutes 40 seconds. With 60 units: together they add 5 units a minute, so 25 units in 5 minutes. A then fills the remaining 35 units at 3 a minute, taking 35/3 = 11 2/3 minutes.
Explain it simply
Split the timeline into phases. In each phase, work out which pipes are open, find the net rate, and compute how much of the tank gets filled. The phases must add up to the whole tank. Most "closed after" or "opened after" questions are just two or three phases.
Example
Question: A fills in 20 min, B in 30 min. Both open for 5 min, then B closed. Extra time for A?
- Tank = LCM(20, 30) = 60 units. A = 3/min, B = 2/min.
- Phase 1 (both, 5 min): 5 x 5 = 25 units.
- Remaining = 35 units.
- Phase 2 (A only): 35 / 3 = 11 2/3 min = 11 min 40 s.
- Total time = 16 min 40 s.
const left = 60 - (3 + 2) * 5;
console.log(left); // Output: 35
console.log((left / 3).toFixed(2)); // Output: 11.67Reverse version: both open, B closed after some time, and the tank is full in 18 minutes. A worked 18 minutes = 54 units, so B did 6 units, which means B was open for 3 minutes.
What to say in the interview
"I split it into phases. Together they fill 25 of 60 units in 5 minutes. A alone does the other 35 at 3 a minute, which is 11 and two thirds minutes, or 11 minutes 40 seconds."
Common mistakes
- Writing 11.67 minutes as 11 minutes 67 seconds.
- Forgetting that A keeps running through both phases in the reverse version.