Pregunta de entrevista de Bloomberg

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