3. What will be the output of the following TypeScript code snippet for
s = "ADOBECODEBANC" and
t = "ABC"?
function minWindow(s: string, t: string): string {
const freqMap = new Map();
for (const ch of t) freqMap.set(ch, (freqMap.get(ch) ?? 0) + 1);
let left = 0, right = 0, count = t.length, minLen = Infinity, start = 0;
while (right < s.length) {
const ch = s[right];
if (freqMap.has(ch)) {
freqMap.set(ch, freqMap.get(ch)! - 1);
if (freqMap.get(ch)! >= 0) count--;
}
while (count === 0) {
if (right - left + 1 < minLen) {
minLen = right - left + 1;
start = left;
}
const leftChar = s[left];
if (freqMap.has(leftChar)) {
freqMap.set(leftChar, freqMap.get(leftChar)! + 1);
if (freqMap.get(leftChar)! > 0) count++;
}
left++;
}
right++;
}
return minLen === Infinity ? "" : s.substring(start, start + minLen);
}
console.log(minWindow(s, t));