Pergunta de entrevista da empresa X

It was a variation of dijkstra.