Howwe are updating the last occurrence because it is always -1 how it is changing it is equated to visited array which have all element as -1

Howwe are updating the last occurrence because it is always -1 how it is changing it is equated to visited array which have all element as -1