Cognizant interview question

Basic programming and aptitude, logical.