Google interview question

How to make it more performant