Ubisoft Interview Question

Algorithm problem, with an attention to memory complexity.