Amtrak interview question

Problem that I helped resolve