Interview Problem - Maximum Length Unique Character Substring | Sliding Window

sir,how is the visited array updating can u give me dry run of visited array?

@17manishms
The visited array is made of size 256 to consider all characters. To make this dry run a bit clear , I am not going to print all 256 values for all iterations but rather the only ones that matter. Note that all the ones that I am not showing over here remain -1 throughout the course for this particular testcase.

Input = " abbacdeb".

Since we know that ASCII value for ‘a’ is 97 , I will only be printing the visited array values for indices 97 to 101 ( corresponding to characters ‘a’ to ‘e’ ). All others remain -1 throughout.

Before beginning the loop after assigning visited[a[0]] = 0;
visited[97] = 0
visited[98] = -1
visited[99] = -1
visited[100] = -1
visited[101] = -1

Inside the loop

After completion of iteration i=1
visited[97] = 0
visited[98] = 1
visited[99] = -1
visited[100] = -1
visited[101] = -1

After completion of iteration i=2
visited[97] = 0
visited[98] = 2
visited[99] = -1
visited[100] = -1
visited[101] = -1

After completion of iteration i=3
visited[97] = 3
visited[98] = 2
visited[99] = -1
visited[100] = -1
visited[101] = -1

After completion of iteration i=4
visited[97] = 3
visited[98] = 2
visited[99] = 4
visited[100] = -1
visited[101] = -1

After completion of iteration i=5
visited[97] = 3
visited[98] = 2
visited[99] = 4
visited[100] = 5
visited[101] = -1

After completion of iteration i=6
visited[97] = 3
visited[98] = 2
visited[99] = 4
visited[100] = 5
visited[101] = 6

After completion of iteration i=7
visited[97] = 3
visited[98] = 7
visited[99] = 4
visited[100] = 5
visited[101] = 6

Final Output = 5

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.