IBM Interview Question

Array based problem on traversing it