Infosys Interview Question

to solve the coding question