Pergunta de entrevista da empresa IBM

Array based problem on traversing it