Pregunta de entrevista de Walmart

Question on topological sorting.