← 返回 amazon 的题目列表Find All Target Anagrams in a Character Stream (Sliding Window)
类型:online_judge
Given a character stream S (lowercase letters arriving one by one) and a target word T of length k, after reading each character you want to know whether the length-k window ending at the current position is an anagram of T.
After consuming the whole stream, output all starting indices (0-based) of matching windows in increasing order.
Input (stdin)
Line 1: string S (the full stream, used to simulate streaming)
Line 2: string T
Output (stdout)
One line containing all starting indices separated by spaces; print an empty line if none.
Constraints
1 <= len(S) <= 2*10^5
1 <= len(T) <= 2*10^5
S and T contain only a-z
Example Input:
cbaebabacd
abc
Output:
0 6
Example
Input
cbaebabacd
abc
Output
0 6