int left = 0 , right = 0 , len = 0 ;
int n = str.size();
while(right<n){
if(mpp[str[right]]!=-1) left = max(left , mpp[str[right]]+1);
mpp[str[right]] = right;
len = max(len , right-left+1);
right++;
}
return len;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter