Cognizant interview question

Write a code in your preferred language