Yandex interview question

Solve the least common ancestor problem