Amazon interview question

Coding a simple bfs and simple follow up