Vio.com Interview Question

How to optimise my solution