Tesla interview question

Searching Algorithm - Used DFS to solve it. I got the output but still rejected after live coding.