Hello i just want to understand and clarify something , i was solving this problem “Longest Substring Without Repeating Characters” , i was using an object as a map but the solution was not accepted , it says time limit exceeded , but when i changed object to a map it works perfectly .
here is the code :
function lengthOfLongestSubstring(s = "") {
let end = 0;
let start = 0;
let maxLength = 0;
const map = new Map();
while (end < s.length) {
if (!map.has(s[end])) {
map.set(s[end], end);
end++;
maxLength = Math.max(maxLength, end - start);
} else {
map.delete(s[start]);
start++;
}
}
return maxLength;
}
thank you 😀