Cognizant interview question

Puzzles and coding