#K47132. Substring Anagram Checker
Substring Anagram Checker
Substring Anagram Checker
Given two strings s1 and s2, determine if there exists any substring of s1 that is an anagram of s2. A substring is a contiguous sequence of characters from s1, and two strings are anagrams if they contain exactly the same characters in the same frequencies. The check is case-sensitive.
Example:
- Input: s1 = "abdcghbaabcdij", s2 = "bcda"
- Output: True
Your solution should read input from standard input (stdin) and output the result to standard output (stdout). Use efficient techniques such as the sliding window method to manage large inputs.
The mathematical condition for an anagram can be expressed in LaTeX as follows:
$$ \text{Anagram}(s2,\, substring) \iff \forall c \in \Sigma, \; \text{freq}_{s2}(c) = \text{freq}_{substring}(c) $$
inputFormat
The input consists of two lines:
- The first line contains the string s1.
- The second line contains the string s2.
Note that either line may be empty.
outputFormat
Output a single line containing either True
or False
. Output True
if there exists any substring of s1 that is an anagram of s2, otherwise output False
.
abdcghbaabcdij
bcda
True