Pergunta de entrevista da empresa Bloomberg

To make a function to which add numbers and optize the solution to decrease time complexity