MindTitan interview question

How to improve code efficiency on a part of my code?