Pregunta de entrevista de Wheely

Classic topological graph sorting. However, the Kahn algorithm cannot be used, as the interviewer doesn't know it.