Cognizant Interview Question

A coding task - pattern question