✅ best C++ fast solution
C++ Code\nC++ []\nclass Solution {\npublic:\n    int lengthOfLongestSubstring(string s) {\n        if(s.length()==0)return 0;   //if string of length zero comes
# C++ Code\n``` C++ []\nclass Solution {\npublic:\n    int lengthOfLongestSubstring(string s) {\n        if(s.length()==0)return 0;   //if string of length zero comes simply return 0\n        unordered_map<char,int> m;   //create map to store frequency,(get to know all unique characters\n        int i=0,j=0,ans=INT_MIN; \n        while(j<s.length())   \n        {\n            m[s[j]]++;  //increase the frequency of the element as you traverse the string\n            if(m.size()==j-i+1)  // whem map size is equal to the window size means suppose window size is 3 and map size is also three that means in map all unique characters are their\n            {\n                ans = max(ans,j-i+1);  //compare the length of the maximum window size\n            }\n            else if(m.size()<j-i+1)   //if the map size is less than the window size means there is some duplicate present like window size = 3 and map size = 2 means there is a duplicates\n            {\n                while(m.size()<j-i+1)  //so till the duplicates are removed completely\n                {\n                    m[s[i]]--;   //remove the duplicates\n                    if(m[s[i]]==0)  //if the frequency becomes zero \n                    {\n                        m.erase(s[i]);//delete it completely\n                    }\n                    i++;  //go for next element \n                }\n            }\n             j++;  //go for the next element\n        }\n        return ans;\n    }\n};\n```\n\n![kitty.jpeg](https://assets.leetcode.com/users/images/fc434770-44aa-4898-b2af-64966ca6e7b1_1678438376.5987267.jpeg)\n
['C++']