Loading section...

Character Frequency Maps: Windows Inside Strings

Concepts: pyFrequencyMap, pyAnagramWindow, pyMatchesCounter

A large class of intermediate sliding window problems involve strings where the window state is not a simple sum or set but a frequency map: a dictionary counting how many times each character appears in the current window. The pattern shows up in anagram detection, permutation matching, and, in data engineering, log token matching and pattern detection in event streams. The mechanics are always the same: when a character enters the window, increment its count; when a character leaves, decrement its count and clean up zeros. Find All Anagrams in a String (LeetCode 438) Given a string s and pattern p, find all starting indices where a permutation (anagram) of p appears in s. This is a fixed-width window of size len(p) over s. The window state is a frequency map of its characters. A window i