Yandex interview question

Problems on two pointers and trees