Parity Energy Interview Question

Traversing tree