/*Write a program to take a string s as input. The task is to find the length of the longest substring without
repeating characters. Print the length as output.*/
#include <stdio.h>
#include <string.h>
int main() {
char s[1000];
int last[256], i, start = 0, maxLen = 0;
memset(last
, -1, sizeof(last
));
for(i = 0; s[i]; i++) {
if(last[(unsigned char)s[i]] >= start)
start = last[(unsigned char)s[i]] + 1;
last[(unsigned char)s[i]] = i;
if(i - start + 1 > maxLen)
maxLen = i - start + 1;
}
return 0;
}
LypXcml0ZSBhIHByb2dyYW0gdG8gdGFrZSBhIHN0cmluZyBzIGFzIGlucHV0LiBUaGUgdGFzayBpcyB0byBmaW5kIHRoZSBsZW5ndGggb2YgdGhlIGxvbmdlc3Qgc3Vic3RyaW5nIHdpdGhvdXQgCnJlcGVhdGluZyBjaGFyYWN0ZXJzLiBQcmludCB0aGUgbGVuZ3RoIGFzIG91dHB1dC4qLwojaW5jbHVkZSA8c3RkaW8uaD4KI2luY2x1ZGUgPHN0cmluZy5oPgoKaW50IG1haW4oKSB7CiAgICBjaGFyIHNbMTAwMF07CiAgICBpbnQgbGFzdFsyNTZdLCBpLCBzdGFydCA9IDAsIG1heExlbiA9IDA7CgogICAgc2NhbmYoIiVzIiwgcyk7CiAgICBtZW1zZXQobGFzdCwgLTEsIHNpemVvZihsYXN0KSk7CgogICAgZm9yKGkgPSAwOyBzW2ldOyBpKyspIHsKICAgICAgICBpZihsYXN0Wyh1bnNpZ25lZCBjaGFyKXNbaV1dID49IHN0YXJ0KQogICAgICAgICAgICBzdGFydCA9IGxhc3RbKHVuc2lnbmVkIGNoYXIpc1tpXV0gKyAxOwoKICAgICAgICBsYXN0Wyh1bnNpZ25lZCBjaGFyKXNbaV1dID0gaTsKCiAgICAgICAgaWYoaSAtIHN0YXJ0ICsgMSA+IG1heExlbikKICAgICAgICAgICAgbWF4TGVuID0gaSAtIHN0YXJ0ICsgMTsKICAgIH0KCiAgICBwcmludGYoIiVkIiwgbWF4TGVuKTsKICAgIHJldHVybiAwOwp9Cg==