Infosys Interview Question

simple train problems and normal coding related