F5 interview question

Perform Breadth First Search and code it