WD interview question

Graph and tree integrated question