Amazon Interview Question

Dynamic Programming and graph question