(80). 26.3. LONGEST SUBSTRING WITHOUT REPEATING CHARACTER. - anishsingh90/Data_Structure_And_Algorithm_In_Cpp_github.io GitHub Wiki
#include <bits/stdc++.h> using namespace std;
int main(){ string s; cout << "Enter character: "; cin >> s;
vector<int> dict(256,-1);
int maxLen = 0, start = -1;
for(int i=0; i<s.size(); i++){
if(dict[s[i]] > start){
start = dict[s[i]];
}
dict[s[i]] = i;
maxLen = max(maxLen,i-start);
}
cout <<"Longest Substring: "<< maxLen;
return 0;
}
/* OUTPUT: Enter character: pwwkew Longest Substring: 3 */