Ubisoft interview question

Algorithm problem, with an attention to memory complexity.