A permutation of s1 appears in s2 if some window of length len(s1) has the same character counts.
Use a fixed-size sliding window over s2. Maintain 26-length frequency arrays for s1 and the current window. Slide by adding the new char and removing the left char.
Two strings are permutations iff their frequency vectors match.
A permutation of s1 appears in s2 if some window of length len(s1) has the same character counts.
Use a fixed-size sliding window over s2. Maintain 26-length frequency arrays for s1 and the current window. Slide by adding the new char and removing the left char.
Two strings are permutations iff their frequency vectors match.