function longestSubString(s) { let result = 0; let leftpointer = 0; const visitedChars = new Map(); for (let rightpointer = 0; rightpointer < s.length; rightpointer++) { while (visitedChars.has(s[rightpointer])) { visitedChars.delete(s[leftpointer]); leftpointer++; } visitedChars.set(s[rightpointer], rightpointer); let width = rightpointer - leftpointer + 1; result = Math.max(result, width); } return result; } there were some issues in your code, the above version should work. Hope it helps :)
```function longestSubString(s) {
let result = 0;
let leftpointer = 0;
const visistedChars = new Map();
for (let rightpointer = 0; rightpointer < s.length; rightpointer++) {
while (visistedChars.has(s[rightpointer])) {
visistedChars.delete(s[rightpointer]);
leftpointer++;
}
let width = rightpointer - leftpointer + 1;
result = Math.max(result, width);
visistedChars.set(s[rightpointer]);
}
return result;
}
console.log(longestSubString("abcbcbdef"))``` it gives me 6
function longestSubString(s) {
let result = 0;
let leftpointer = 0;
const visitedChars = new Map();
for (let rightpointer = 0; rightpointer < s.length; rightpointer++) {
while (visitedChars.has(s[rightpointer])) {
visitedChars.delete(s[leftpointer]);
leftpointer++;
}
visitedChars.set(s[rightpointer], rightpointer);
let width = rightpointer - leftpointer + 1;
result = Math.max(result, width);
}
return result;
}
there were some issues in your code, the above version should work. Hope it helps :)