Cognizant interview question

Writing a code