Cognizant Interview Question

A program was given and I was asked to write logic.Also a puzzle was given to be solved