Pergunta de entrevista da empresa Bloomberg

What's the best way to optimize a given code & Time and Space complexities.