Pregunta de entrevista de Amazon

Leet code question similar to course schedule II.