LogiQuest

418. Find All Anagrams in a String

MediumSliding Window

Print every 0-based start index in s where an anagram of p begins, in increasing order, or NONE.

Input format

Line 1: s Line 2: p

Output format

The indices or NONE.

Example 1

Input

cbaebabacd
abc

Output

0 6

Example 2

Input

abab
ab

Output

0 1 2

Constraints

1 ≤ |s|, |p| ≤ 10⁴

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…