class Solution {
public int longestSubstringWithoutDuplication(String s) {
int freq[]=new int[128];
int i=0,j=0,res=0;
while(j<s.length()) {
char c1=s.charAt(j);
freq[c1]++;
j++;
while(freq[c1]>1){
char c2=s.charAt(i);
freq[c2]--;
i++;
}
res=Math.max(res,j-i);
}
return res;
}
}