Amazon interview question

Graph question with DP problem