Valeo Interview Question

Train based type problem