Pregunta de entrevista de Palantir Technologies

Difficult Algorithm question.