Tech Mahindra interview question

problems on trains and streams...comprehension