Find Anagrams Window
Python data engineering interview problem. Difficulty: intermediate. Pattern: Sliding Window. About 14 minutes. Part of the full drill bank.
Same behavior as find_anagrams: start indices of anagram windows. Treat this as a production helper: match the contracted return shape, including empty and duplicate inputs.
Another log search needs the same anagram-window operation, but it uses a different function name. The important part is the exact window contract, not the name of the helper you may have written earlier. Find every start index where a substring of s is an anagram of p. Return indices in ascending order, including overlapping matches, with no extra indices. Write the function find_anagrams_window(s: str, p: str) -> list. For 'cbaebabacd' and 'abc', the matching windows are cba at 0 and bac at 6, giving [0, 6]. The starter file already has the function name and the harness print lines. Keep them, and fill only the function body.
Requirements
- Use windows of exactly len(p) characters.
- Match character counts, not only the set of characters.
- Return every valid starting index once and keep ascending order.
Constraints
- The return type is a list of integers and matching is case-sensitive.
- The input can contain overlapping anagrams and may have no match.
Examples
Input: find_anagrams_window('cbaebabacd', 'abc') Output: [0, 6] Same hits as find_anagrams.
Topics: lakebench, python, anagram, window.
More Python interview questions · All interview problems · Learn data engineering
Find Anagrams Window
Interview-style drill: Same behavior as find_anagrams: start indices of anagram windows.
Implement `find_anagrams_window(s: str, p: str) -> list` with the same behavior as `find_anagrams`. Example: `"cbaebabacd", "abc"` → `[0, 6]`. Keep the harness.