Infosys interview question

Write the code for BFS