Amazon Interview Question

Quite difficult, algorithms and data structures. Dynamic programming, then BFS backtracking