Infosys Interview Question

Coding question simply asked to solve