Pregunta de entrevista de Cognizant

Coding question based on array