Visualize the sliding window algorithm to find if a permutation of one string exists as a substring of another
Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.
In other words, return true if one of s1's permutations is the substring of s2.
Example:
Two strings are permutations of each other if and only if they have the same character frequencies. Instead of generating all permutations of s1 (which would be factorial time complexity), we can use a sliding window of size len(s1) on s2 and compare character frequencies at each position.
The sliding window technique is perfect for this problem because: