Thoughtworks Interview Question

Q: Can you optimise the solution?