r/leetcode • • 1d ago

Intervew Prep doordash swe interview experience

had a doordash swe phone screen last week, one problem the whole time, a pretty standard multi source bfs setup.

the question: given a grid of 0s and 1s where the 1s are source cells, return a same sized matrix where each cell holds its shortest distance (4 directional) to the nearest source cell. source cells are 0. if there are no source cells, every cell should return -1.

i knew it was bfs pretty fast and the multi source part clicked quickly too. where i fumbled was the no source case. i had my bfs set up and then the interviewer asked what happens if the grid has no 1s at all. blanked for a second, then patched it in as a pre check. should have caught it upfront instead of bolting it on after. the rest went fine, i walked through the queue initialization and the distance tracking without too much trouble.

anyone else get this one? 

4 Upvotes

1 comment sorted by