Rapleaf Interview Question

How to optimize BFS?