Infosys Interview Question

Writing a simple code and explain