#C6816. Anagram Prefix Detection
Anagram Prefix Detection
Anagram Prefix Detection
Given two strings, P (called the prefix) and T (the text), determine whether any anagram of P is a prefix of T. In other words, if we denote m = |P| and n = |T| and consider the substring T[0:m] (i.e. the first m characters of T), check if this substring is a permutation (anagram) of P.
This can be mathematically expressed as checking if:
\( \text{Freq}(P) = \text{Freq}(T[0:m]) \)
where \( \text{Freq}(X) \) denotes the frequency count of characters in string \( X \).
inputFormat
The input consists of two lines:
- The first line contains the string P (prefix).
- The second line contains the string T (text).
You can assume that the strings only contain standard printable characters without spaces.
outputFormat
Output a single line containing either True
or False
(case-sensitive), indicating whether an anagram of P is a prefix of T.
abc
cbaebabacd
True
</p>