Pergunta de entrevista da empresa Walmart

Question on topological sorting.