Amazon Interview Question

Question on dp and graphs with tc