Amazon interview question

Leetcode style Q - course schedule II (medium difficulty)