Bloomberg Interview Question

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