3. Longest Substring Without Repeating Characters

Run Settings
LanguageJavaScript
Language Version
Run Command
var lengthOfLongestSubstring = function(s) { let op = []; let longestSubStr = 0; s.split('').map((el,i) => { let matchIndex = op.indexOf(el); if(matchIndex == -1){ op.push(el); }else{ //console.log("BEFORE-->",op) longestSubStr = op.length > longestSubStr? op.length : longestSubStr; op.splice(0,matchIndex+1); op.push(el); //console.log("AFTER-->",op,longestSubStr) } }); return op.length > longestSubStr? op.length : longestSubStr; }; console.log(lengthOfLongestSubstring("abcabcbb")); //"pwwkew" - 3 //"aab" -2 //"abcabcbb" -3
Editor Settings
Theme
Key bindings
Full width
Lines