When To Choose BFS Over DFS? (Essential For Coding Rounds)

Posted
20 Nov 2025
366 reads

Summary

I participated in an on-campus coding round with Samsung where I encountered a challenging graph problem. The experience highlighted the critical importance of choosing BFS over DFS for problems involving shortest paths or levels, as candidates using BFS achieved a perfect score on the problem.

How it went

I recently participated in an actual on-campus coding round conducted by Samsung at my college. In Round 1, we were given 3 hours to solve a single problem. The question involved a square matrix, seven types of pipes, each allowing movement in specific directions, a starting position, and the task was to compute the maximum number of reachable steps from that position through valid pipe connections.

Many of my peers attempted this problem using DFS. Out of 50 test cases, those who used DFS typically passed around 42. However, candidates who used BFS received a perfect 50/50. That round made one thing crystal clear to me: while DFS can explore, BFS guarantees correctness whenever distance, levels, or minimal steps matter. This insight led me to understand exactly why BFS worked flawlessly in that problem, and more importantly, when BFS is the right tool.

Questions asked (1)

  1. 01

    Max Reachable Steps in Pipe Matrix

    Data Structures & Algorithms · Hard

    Given a square matrix and seven distinct types of pipes, each type allowing movement in specific directions. From a designated starting position within the matrix, the task is to compute the maximum number of reachable steps through valid pipe connections. The problem implies finding the farthest reachable node in a graph where nodes are matrix cells and edges are valid pipe connections.

Know someone preparing? Send it to them:WhatsAppLinkedInX

Interviewed at Samsung recently?

Write up your rounds while you still remember the questions. It helps the next person more than you would think.

Share your experience
Discussion 0

Questions for the author, or how your own interview compared.

Join the discussion

Sign in with Google to comment or ask the author a question.

No comments yet

Be the first to share your thoughts and start the discussion!