Cognizant Interview Question

Gave to write a code