SAP interview question

BFS DFS related algorithmic problem