Vio.com interview question

How to optimise my solution