Infosys Interview Question

During the coding questions, asked some modifications and rewrite the code.