Apple Interview Question

A BFS type algorithm question