Amazon interview question

leetcode hard, graph problem, optimal not expected