Pregunta de entrevista de Fanatics

Algorithm question regarding creating a graph