#K52152. Anagram Finder and Inclusion Checker
Anagram Finder and Inclusion Checker
Anagram Finder and Inclusion Checker
You are given two strings, \( s \) and \( p \). Your task is two-fold:
- Find all starting indices in \( s \) of any anagram of \( p \). An anagram is a permutation of the string \( p \).
- Determine whether any anagram of \( p \) is present as a substring in \( s \).
For example, if \( s = "cbaebabacd" \) and \( p = "abc" \), then the anagrams of \( p \) that appear in \( s \) start at indices 0 and 6. Since at least one anagram exists, the answer for the inclusion check is True
.
Note: If no anagram is found for the first task, output an empty result (i.e. a blank line for the list of indices) and False
for the inclusion check.
inputFormat
The input consists of two lines:
- The first line contains the string \( s \).
- The second line contains the string \( p \).
Both strings consist of lowercase English letters.
outputFormat
The output should contain two lines:
- The first line prints all starting indices (0-indexed) where an anagram of \( p \) begins in \( s \). Indices should be separated by a single space. If no anagram exists, output an empty line.
- The second line prints
True
if at least one anagram of \( p \) is found as a substring in \( s \), otherwise it printsFalse
.
cbaebabacd
abc
0 6
True
</p>