Backend Engineer | Zenskar
JP Morgan Chase | SDE 3 | YOE 3.4
Microsoft SDE - 2 | Interview Experience | Status Pending
eBay || SWE3 Interview Experience || Bangalore
Bloomberg | Interview Experience | Senior Software Engineer | NYC | Nov 2025
When To Choose BFS Over DFS? (Essential For Coding Rounds)
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.
Full Experience
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.
Interview Questions (1)
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.