I understood why we are checking for a match and if they reach 0 its correct. when decreasing the window size why are we putting the element back in?
if (windowEnd >= pattern.length() - 1) { // shrink the window by one character
char leftChar = str.charAt(windowStart++);
if (charFrequencyMap.containsKey(leftChar)) {
if (charFrequencyMap.get(leftChar) == 0)
matched--; // before putting the character back, decrement the matched count
// put the character back for matching
charFrequencyMap.put(leftChar, charFrequencyMap.get(leftChar) + 1);
}
}