Not able to understand visited array

the code discussed in this video uses code given on link :

In this code, why size of visited array is 256 and also how assignment is done visited [a[0]] = .0;
a is a character array, how can its characters can become indexes. Please also explain the intuition behind this code

Because there are only 256 characters in c++

This means because a[0] has character value right? So a[0] has some character value which is mapped on visited array. For eg if a[0] is =a, then visited[a] is equal to 0. where a has some value between 256 to 0.

This solution uses extra space to store the last indexes of already visited characters. The idea is to scan the string from left to right, keep track of the maximum length Non-Repeating Character Substring seen so far in res . When we traverse the string, to know the length of current window we need two indexes.

  1. Ending index ( j ) : We consider current index as ending index.
  2. Starting index ( i ) : It is same as previous window if current character was not present in the previous window. To check if the current character was present in the previous window or not, we store last index of every character in an array lasIndex[] . If lastIndex[str[j]] + 1 is more than previous start, then we updated the start index i. Else we keep same i.

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.