Amazon Interview Question

Bfs graph traversal along with memoization