Your question is Real-Time Anagram Detection. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Amazon Kinesis can deliver text as a sequence of chunks rather than one complete string. Given an iterable of lowercase English text chunks and a lowercase target word, find every starting character index where a contiguous window is an anagram of the target.
Process chunks in order without concatenating the entire stream. Windows may begin in one chunk and end in another. Return starting indices in the complete logical stream, ordered from left to right.
Implement find_stream_anagrams(stream, target), where stream is an iterable of strings containing only lowercase letters and target is a non-empty lowercase string. Return a list of integers. Each integer is the zero-based starting index of a window whose length equals len(target) and whose character frequencies exactly match the target frequencies.
Use a fixed-size frequency array for the 26 lowercase letters. The implementation should retain only the current window, not the entire stream.
def find_stream_anagrams(stream, target):