Samsung Electronics Interview Question

Based on graphs - BFS, DFS