Cognizant interview question

Coding question based on array