Amazon Interview Question

Question 1 was based on tree traversal