Breadth First Search
Problems and Patterns
CodeStory tags 157 problems as Breadth First Search, and 100 of them are Medium. Learn the queue trick, then solve the ten most asked.
Sign up free and receive 100 AI credits, then 100 more monthly.
How the Breadth First Search Pattern Works
CodeStory covers the tell, the queue mechanism and the weight mistake.
Spot the tell. You need the shortest path in steps, or your problem spreads out one layer at a time. Study CodeStory's Breadth First Search guide before you code.
Learn the mechanism. Use a queue and a seen set. Everything one step away comes out before anything two steps away, so you reach a node first by the shortest route. Practise the queue in CodeStory's queue problems and grid walks in its matrix problems.
Avoid the mistake. BFS finds the shortest path only when every edge has the same weight. Edges with different weights call for Dijkstra, which you can step through in CodeStory's Dijkstra visualiser.
Most Asked Breadth First Search Problems
CodeStory lists these by how many companies set them.
- Walls and GatesMedium7 companies
- Shortest Path in a Grid with Obstacles EliminationHard6 companies
- Number of Connected Components in an Undirected GraphMedium3 companies
- Find the Safest Path in a GridMedium2 companies
- As Far from Land as PossibleMedium2 companies
- Island PerimeterEasy1 company
- Detonate the Maximum BombsMedium1 company
- Find All Groups of FarmlandMedium1 company
- Minimum Cost to Make at Least One Valid Path in a GridHard1 company
- Minimum Number of Operations to Make X and Y EqualMedium1 company
Study, Watch and Solve Breadth First Search
Follow CodeStory's order to make layers stick.
More to Practise Inside the App
CodeStory pairs patterns with interviews and career tools. Swipe for more.
Technique Drills
Drill one technique before you move to the next.
352 problemsOpenHiring Company Sets
Practise what a named company asks.
463 companiesOpenLive Coding Interview
Choose a role and code while questions arrive.
scored reportOpenVoice Interview Rounds
Speak your answers and meet follow ups.
32 topicsOpenDBMS Viva Prep
Face index, join and normalisation questions.
in Core CSOpenOOP Viva Prep
Defend your inheritance and polymorphism answers.
in Core CSOpenSystem Design Chapters
Study how systems get built, layer by layer.
27 chaptersOpenSQL Challenges
Query real tables and check every row.
39 questionsOpenAptitude Tests
Quant, logic, verbal and DI under a timer.
280 questionsOpenTimed Coding Assessments
Practise with marks and hidden tests.
37 papersOpenAlgorithm Animations
Follow every step on input you choose.
26 algorithmsOpenGuided AI Hints
Reveal hints gradually before you ask for review.
100 free creditsOpenResume Maker
Build your resume beside your practice record.
in the appOpenReadiness Score
See one score and your weakest area.
tracked dailyOpen
Sign up to collect 100 AI credits, then 100 more monthly. Start free in the app
BFS Problems FAQs
Start free with no card, or ask a mentor on a free call.
Start Practising BFSHow do I know a problem is a BFS problem?
CodeStory looks for two signs. You need the shortest path in steps, or your problem spreads out one layer at a time.
How many BFS problems should I solve?
CodeStory recommends ten to fifteen across the levels, which is enough to stop needing the hint. CodeStory shows all 157 tagged problems, split 15 Easy, 100 Medium and 42 Hard, so expect mostly Medium.
Which mistake costs the most in BFS problems?
Using BFS for shortest path when edges have different weights costs the most. Those problems need Dijkstra.
Why does BFS find the shortest path?
BFS visits everything one step away before anything two steps away, so the first time you reach a node is by the shortest route.
Is practising by pattern better than a problem sheet?
Yes. Sheets give you problems in a row, while CodeStory's patterns show you what links them, and that link carries over to problems you have not seen. CodeStory files every problem under its pattern.
Which BFS problems do companies ask most?
Walls and Gates leads, asked at 7 companies in CodeStory's catalogue. Next comes a grid problem with obstacles, asked at 6 companies.
Is BFS practice free to start?
Yes. CodeStory needs no card, gives you 100 AI credits at signup and adds 100 every month.
Want Guided BFS Practice? Get a Free Callback
Describe your target role to CodeStory, and a mentor lines up your path.
- 1CodeStory rates your level, from beginner to interview ready.
- 2CodeStory explains online and campus batches, with timings that fit your schedule.
- 3You decide. No pressure, no payment on the call.