Amazon Interview Question

Graph question with DP problem