Amazon Interview Question

Tree traversal problem