function findLongestUnrepeatSubString(S) { let start = 0, maxLength = 0; const map = new Map(); for (let i = 0;i < S.length;i++) { const letter = S.charAt(i); if (map.has(letter)) { if (map.size > maxLength) { maxLength = map.size; start = i - map.size; } const prev = map.get(letter); i = prev; map.clear(); continue; } map.set(letter, i); } return S.slice(start, start + maxLength); } console.log(findLongestUnrepeatSubString("abackwppa"))