#K33127. Find All Anagrams in a String

    ID: 25019 Type: Default 1000ms 256MiB

Find All Anagrams in a String

Find All Anagrams in a String

You are given two strings s and t. Your task is to find all starting indices in s where an anagram of t begins. An anagram is a permutation of characters. For instance, if t = abc, then any substring of s that is a permutation of 'a', 'b', and 'c' is considered an anagram of t.

The indices should be output in ascending order. If no such substring exists, output an empty line.

Note: Both input strings consist of lowercase English letters.

Input Format: The first line of input contains the string s and the second line contains the string t.

inputFormat

The input consists of two lines:

  1. The first line contains the string s.
  2. The second line contains the string t. Both strings contain only lowercase English letters.

outputFormat

Output the starting indices (0-indexed) of t's anagrams in s in ascending order, separated by a single space. If there are no anagrams, output an empty line.## sample

cbaebabacd
abc
0 6