Amazon interview question

Similar to the course schedule question on leetcode.