FxPro Group interview question

How can you optimise this solution?