Cognizant interview question

Program logics for a questions