Pregunta de entrevista de Amazon

Graph related question and stack.