Pergunta de entrevista da empresa Yandex

Problems on two pointers and trees