IBM interview question

Array based problem on traversing it