Parity Energy interview question

Traversing tree