Cognizant interview question

Gave to write a code