438. Find All Anagrams in a String - LeetCode
from collections import Counter
class Solution:
def findAnagrams(self, s: str, p: str) -> list[int]:
result, s, P = [], s + ' ', len(p)
cp, cs = Counter(p), Counter(s[:P])
for i in range(len(s) - P):
if cp == cs:
result.append(i)
cs.subtract(s[i])
cs.update(s[i + P])
return result