Bloomberg Interview Question

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