Pregunta de entrevista de Ubisoft

Algorithm problem, with an attention to memory complexity.