Pregunta de entrevista de Amazon

graphs problem could not able to solve