This solution uses a sliding window approach to determine if a permutation of string s1 is present in string s2. We maintain two frequency arrays: one for s1 (f1) and another for the current window of characters in s2 (f2). Both arrays track the frequency of each letter in the alphabet (26 positions, one for each letter). As the window moves across s2, we update f2 by adding the current character and removing the one that falls out of the window. After each update, we compare f2 to f1. If they match, it means a permutation of s1 is found in the current window of s2, and we return true. If no such match is found by the end of s2, the function returns false.
Added day 05 solution file in javascript
This solution uses a sliding window approach to determine if a permutation of string
s1
is present in strings2
. We maintain two frequency arrays: one fors1
(f1
) and another for the current window of characters ins2
(f2
). Both arrays track the frequency of each letter in the alphabet (26 positions, one for each letter). As the window moves acrosss2
, we updatef2
by adding the current character and removing the one that falls out of the window. After each update, we comparef2
tof1
. If they match, it means a permutation ofs1
is found in the current window ofs2
, and we returntrue
. If no such match is found by the end ofs2
, the function returnsfalse
.