Maximum substring length using sliding window

I did not undertsand how mapping is being done using array.

visited[i]=-1 is being initialized and then later we are writing

last_occ=visited[a[i]] so what value are we exactly storing in last_occ?

also in the else statement what will be value of last_occ?

PLz explain

@aryamaan1011
hello aryamaan,
the purpose visited array is to store the position of last occurrence of the character .
so when we do last_occ=visited[a[i]] then last_occ will contain position of last occurrence of character a[i].
also please post the code that u are referring so that i can answer ur other queries.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.