Valeo interview question

Train based type problem