Google interview question

question was from topic MultiSource BFS questions