Pergunta de entrevista da empresa Interactive Brokers

Just started with average array questions and then asked for their optimization.