#K58632. Find Shuffled Substrings
Find Shuffled Substrings
Find Shuffled Substrings
You are given two strings s
and t
. Your task is to find all starting indices in the string s
where a substring of length equal to t
forms a permutation (i.e. a shuffled version) of t
. In other words, you need to check every contiguous substring of length \( m \) (where \( m \) is the length of t
) in s
and print its starting index if the substring contains exactly the same characters as t
in any order.
If no such substring exists, output -1
.
Example:
Input: cbabcacab abc</p>Output: 0 2 3 6
Note: The answer should be printed as a space-separated list of indices.
inputFormat
The input consists of two lines. The first line contains the string s
. The second line contains the string t
.
outputFormat
Output the starting indices of all substrings of s
which are valid permutations (shuffled versions) of t
as a space-separated list. If no valid substring is found, print -1
.
cbabcacab
abc
0 2 3 6