diff --git a/lengthLongestSubstringWithoutRepeatingCharacters.cpp b/lengthLongestSubstringWithoutRepeatingCharacters.cpp new file mode 100644 index 0000000..d1fac6d --- /dev/null +++ b/lengthLongestSubstringWithoutRepeatingCharacters.cpp @@ -0,0 +1,39 @@ + +#include + +using namespace std; + + int lengthOfLongestSubstring(string s) { + int j=0; + //if(s.size()==0) + // return 0; + mapmp;int ans=0; + for(int i=0;i 0) + { + while(mp[s[i]]!=0) + { + mp[s[j]]--; + j++; + } + } + + ans = max(ans,i-j+1); + mp[s[i]]++; + } + return ans; + } +int main() +{ + int t; + cin>>t; + while(t--) + { + string s; + cin>>s; + int ans= lengthOfLongestSubstring(s); + cout<