Infosys interview question

Writing a simple code and explain