Yandex interview question

LeetCode medium question on binary tree