Amazon interview question

graphs and trees