Pergunta de entrevista da empresa J.P. Morgan

Which data structure is more suitable for this problem(based on the 1st written exercise)?