Reputation Interview Question

Tree traversal problem