Amazon interview question

Question on dp and graphs with tc