You are viewing a single comment's thread. Return to all comments →
Here is my approach via JS. I just check each possible pair by splitting the rest of the characters out.
let c1; let c2; let longest = 0; for(let i = 0; i < s.length; i++){ if(s.indexOf(s.charAt(i)) === i){ c1 = s.charAt(i); for(let j = i + 1; j < s.length; j++){ let str = s; if(s.indexOf(s.charAt(j)) === j){ c2 = s.charAt(j); for(let k = 0; k < s.length; k++){ if(s.indexOf(s.charAt(k)) === k){ let c3 = s.charAt(k); if(c3 !== c1 && c3 !== c2){ let arr = str.split(c3); str = arr.join(``); } } } if(str.length > longest) { longest = getLengthIfValid(str); } } } } } return longest; function getLengthIfValid(str){ for(let i = 0; i < str.length - 1; i++){ if(str.charAt(i) === str.charAt(i+1)){ return longest; } } return str.length; }
Seems like cookies are disabled on this browser, please enable them to open this website
Two Characters
You are viewing a single comment's thread. Return to all comments →
Here is my approach via JS. I just check each possible pair by splitting the rest of the characters out.