Pregunta de entrevista de Yandex

Some deep details about how to optimise algorithm using tree, cannot recall correctly