The streaming angle messed with my head more than it should have.
Use a sliding window of length equal to T's length, and compare character frequency counts between the window and T. Optimize by updating counts incrementally as the window slides, achieving O(n) time.
Pro tip: Mention that you can avoid recomputing the entire frequency array by updating only the characters entering and leaving the window, and use a match counter to track how many characters have the correct frequency.
Restate the problem to ensure understanding: find all starting indices where a substring of S of length |T| is an anagram of T. Confirm edge cases like empty strings or T longer than S.
Use frequency arrays (size 26 for lowercase letters) or hash maps to count characters in T and in the current window of S.
Initialize the window with the first |T| characters of S. Slide the window one character at a time: remove the leftmost character, add the new rightmost character, and update the frequency counts accordingly.
Maintain a counter of how many characters have the exact required frequency. When the counter equals the number of distinct characters in T, the current window is an anagram; record its starting index.
State time complexity O(n) and space O(1) (since alphabet size is fixed). Walk through a small example to verify correctness, including edge cases.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.