Infosys interview question

One code need to optimise