Loading section...
Frequency Counting + Sliding Window: The Power Combo
Concepts: pyWindowCounter, pyAnagramSlide, pyDiffCount
When frequency counting meets sliding windows, the result is one of the most elegant patterns in coding interviews. The canonical problem: 'Find All Anagrams in a String' (LeetCode 438). You have a string s and a pattern p. Find all starting indices in s where a substring of length len(p) is an anagram of p. The naive approach: for every window of size len(p), build a Counter and compare. That is O(n * m) where m = len(p). The efficient approach maintains a Counter of the current window and updates it as the window slides, comparing frequencies with the pattern Counter. O(n) total. Find All Anagrams in a String (LeetCode 438) Walk through the complexity: building p_count is O(m). Building the first window is O(m). Each slide is O(1) — one increment, one decrement, one delete. The compariso