Yandex Interview Question

Algorithmic task on tree traversal