YouTube interview question

A breadth-first search related problem