Infosys Interview Question

One code need to optimise