Skip to content

Breadth-First Search problems,
and the tell.

You need the shortest path in steps, or anything that spreads out one layer at a time. 157 problems in the catalogue carry this tag, from first-week easy to interview hard.

Free to start. Running and submitting a solution never costs credits.

How the pattern actually works.

One mechanism, and the mistake that costs people the problem.

The tell. You need the shortest path in steps, or anything that spreads out one layer at a time.

The mechanism. A queue, and a seen set. Everything one step away comes out before anything two steps away, so the first time you reach a node is by the shortest route.

What goes wrong. Using BFS for shortest path when the edges have different weights. That is Dijkstra, not BFS.

The ones asked most often.

By how often the catalogue records them being set, not by our opinion.

  1. Walls and GatesMediumasked at 7 companies
  2. Shortest Path in a Grid with Obstacles EliminationHardasked at 6 companies
  3. Number of Connected Components in an Undirected GraphMediumasked at 3 companies
  4. Find the Safest Path in a GridMediumasked at 2 companies
  5. As Far from Land as PossibleMediumasked at 2 companies
  6. Island PerimeterEasyasked at 1 companies
  7. Detonate the Maximum BombsMediumasked at 1 companies
  8. Find All Groups of FarmlandMediumasked at 1 companies
  9. Minimum Cost to Make at Least One Valid Path in a GridHardasked at 1 companies
  10. Minimum Number of Operations to Make X and Y EqualMediumasked at 1 companies

Read it, watch it, then solve it.

The order that makes a pattern stick.

Everything in the app, in one place.

Practice, interviews and the tools, all free to start. Swipe to see the rest.

Free to start: 100 AI credits when you sign up and 100 every month. Start free in the app

About breadth-first search problems.

Free to start, no card.

Start practising
How do I know a problem is a breadth-first search problem?

You need the shortest path in steps, or anything that spreads out one layer at a time.

How many breadth-first search problems should I solve?

Enough to stop needing the hint, which is usually ten to fifteen across the levels, not the whole list. The catalogue tags 157, split roughly 15 easy, 100 medium and 42 hard in the sample we show, so work up rather than across.

What goes wrong most often in breadth-first search problems?

Using BFS for shortest path when the edges have different weights. That is Dijkstra, not BFS.

Is practising by pattern better than a problem sheet?

A sheet tells you what to solve. A pattern tells you why those problems sit together, which is the part that carries over to the problem you have not seen. That is why the app files every problem under its pattern.