LinkedIn interview question

Write a function to implement BFS.