Domanda di colloquio di Amazon

Leet code question similar to course schedule II.