Google Interview Question

question was from topic MultiSource BFS questions