Why is BFS better than DFS for this problem ?


  • 2
    N

    I can see that BFS based solutions are able to pass the tests but the DFS based solutions are failing (I am getting stack overflow). Any particular reason as to why BFS should be preferred here ?


  • 2

    In fact, in my test, DFS faster than BFS in this problem. I think you getting stack overflow because you have consider the peripheral border again in DFS, it is unnecessary.

    Please get more information from here.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.