Cognizant interview question

some aptitude and coding qn