✅Short||C++||Expained Solution|| 11 line code
Intuition\n Describe your first thoughts on how to solve this problem. \nWe have to find the length of longest substring which does not contain any repeating ch
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nWe have to find the length of longest substring which does not contain any repeating characters\n\nThe first thing which should come in our mind is to traverse in the string and store the frequence of each character in a map type of "map<char ,int>" and try to maintain frequency of all the characters present in the map to 1 and storing the maximum length \n\n\n# Approach\n1:- We will first iterate over the string and store the frequencies of all the character we have visited in a map of type "map<char ,int>"\n\n2:- In each iteration we will check if the frequency of character at ith index is greater than one.....if yes it means that that character is repeated twice in our map so we will start erasing all the characters from the starting jth index untill we delete the same character which is repeated twice...... from the left\n\nex :- `Input: s = "abcabcbb"`\n\n`i=0 mp:{[a:1]}`\n|| length =1 , maxlength = 1  \n\n`i=1 mp:{[a:1] , [b:1]}`\n|| length =2 , maxlength = 2\n\n`i=2 mp:{[a:1] , [b:1] , [c:1]}`\n|| length =3 , maxlength = 3\n\n`i=3 mp:{[a:2] , [b:1] , [c:1]}`\n|| length =4 , maxlength =3\n\n\'a\' appeared 2 times , so we will start removing characters from the left untill the frequency of \'a\' becomes 1 again.\nwhile(mp[a]>1) , we will decrease the frequency of all the characters from left i.e. "mp[s[j++]]--" ......Variable j stores the starting index of our subarray , Initially it is 0 but as we start deleting characters from left , this j will be get increment....that is why we did j++ there.\nwhen j=0 , mp[s[j++]] will get decrease by one and the frequency of a will again be equal to 1\n\n`i=3 mp:{[a:1] , [b:1] , [c:1]}`\n|| length =3 , maxlength =3\n\n3:- In each iteration we will take the maximum of (maxlength ,length) and store it in max length\n\nThis process will continue till we reach the end of the string and will return maxlength which is the length of longest substring with no repeating characters in it \n\n\n\n\n# Code\n```\n    int lengthOfLongestSubstring(string s) {\n        int length=0 , maxlength=0,j=0;\n        map<char ,int> mp;\n        for(int i=0 ;i<s.size(); i++){\n            mp[s[i]]++;\n            length++;\n                while(mp[s[i]]>1){\n                    mp[s[j++]]--;\n                    length--;\n                }\n            maxlength = max(maxlength,length);\n        }\n        return maxlength;\n    }\n```\n\n# Please do upvote if you like the Explanation
['Two Pointers', 'String', 'Sliding Window', 'C++', 'Java']