We use cookies for site analytics. Accept to help us understand how the site is used. See our Privacy Policy for details.
BFS visits everything one step away, then two steps away, which means the first time it reaches a node it has reached it by the shortest route. In an unweighted graph or grid that property is the whole answer. The words minimum number of moves in a problem statement should make you reach for a queue before you finish reading the sentence.
"Shortest path", "minimum number of steps", or anything needing level order.
18 problems. Each one runs in an in-browser editor against real test cases, with hints and a worked solution.
The patterns cheat sheet covers all of these in one page - what each one looks like in a problem statement, and the template that follows.