LTM Limited interview question

To optimize my previous code from their online test