Rapleaf interview question

How to optimize BFS?