Amazon Interview Question

Coding a simple bfs and simple follow up