SAP Interview Question

BFS DFS related algorithmic problem