0% completed
Hi, most of this makes sense besides the following line.`if (charFrequencyMap.ge...
John Moon
Sep 14, 2022
Hi, most of this makes sense besides the following line.
if (charFrequencyMap.get(leftChar) == 0)
We are searching for duplicate char's if we already matched on a char. However, shouldn't we be checking for -1?
E.G if we're looking for findSubstring("aabdec", "abc") example, after rightChar matching on "a" twice, the charFrequencyMap would return -1 for "a".
Why is it charFrequencyMap.get(leftChar) == 0 instead of charFrequencyMap.get(leftChar) < 0
Thank you
0
0
Comments
Bharpur Singh3 years ago
Hello John charFrequencyMap.get(leftChar) will get negative when we have more than required characters in str. Hence, we will only decrease matched variable when we are lacking that character from the current window. It can also be said we are ignoring redundant chars a...
On this page