Amazon interview question

Tree traversal question