From df8eb9684513ca5b4a6ea9db444f90e4efd1729e Mon Sep 17 00:00:00 2001 From: Praggya17 <71866834+Praggya17@users.noreply.github.com> Date: Sun, 29 Oct 2023 00:25:38 +0530 Subject: [PATCH] Create lengthLongestSubstringWithoutRepeatingCharacters.cpp --- ...estSubstringWithoutRepeatingCharacters.cpp | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lengthLongestSubstringWithoutRepeatingCharacters.cpp 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<