0% completed
Why do we need to delete the leftCharacter once its frequency reaches 0?
florian.vogt
Mar 18, 2022
Why do we need to delete the leftCharacter once its frequency reaches 0?
0
0
Comments
Design Gurus4 years ago
Because we want to bring the size of charFrequencyMap equal to 'K' while shrinking the window. If we don't delete the leftChar from the map when its frequency is zero, our frequency map will not shrink.
Siri 4 years ago
what exactly this Map.put doing in this program? charFrequencyMap.put(rightChar, charFrequencyMap.getOrDefault(rightChar, 0) + 1);
florian.vogt 4 years ago
Could this also be solved using a set instead of a hash map?
Tiago Machado3 years ago
I have the same feeling that it can be solved with a set, but still haven't found how to to do it
Victor Lee3 years ago
dont think a set would work because you would be unable to track how many dupes
Design Gurus3 years ago
We can't use a set, as we need to keep track of the frequency of each character.
On this page