Cognizant Interview Question

Simple ds problem and programming