Siemens interview question

Dfs algorithm