Reputation interview question

Tree traversal problem