Amazon Interview Question

graphs and trees