arya2004 / leetcode-daily-october-hacktoberfest-2024

Leetcode Daily October Hacktoberfest 2024
MIT License
10 stars 49 forks source link

Create solution_javascript.js #37

Closed ssugam10 closed 1 month ago

ssugam10 commented 1 month ago

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 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.

arya2004 commented 1 month ago

lgtm @ssugam10