DMAI interview question

Solve DFS in preferred language.