function numKLenSubstrNoRepeats(str, k) { if (!str) { return 0; } let l = 0, r = 0, total = 0; const n = str.length; const smap = new Map(); while (l < n && r < n) { if(!smap.has(str.charAt(r))) { smap.set(str.charAt(r), r); r++; } else { smap.delete(str.charAt(l)); l++ } if (smap.size === k) { total++; smap.delete(str.charAt(l)); } } return total; } console.log(numKLenSubstrNoRepeats('havefunonleetcode', 5))