Anyone can see why the overtake distance is both lengths and why same-direction speeds subtract
"The faster train zooms past in a few seconds" (and the habit of adding speeds from opposite-direction questions)
The shortcut: add the lengths, then subtract the speeds for the same direction, or add them for opposite directions.