Cognizant Interview Question

Coding question based on array