Infosys interview question

simple train problems and normal coding related