#K49202. Check Inclusion of Permutation

    ID: 28590 Type: Default 1000ms 256MiB

Check Inclusion of Permutation

Check Inclusion of Permutation

Given two strings, pattern and text, determine if text contains any permutation of pattern as a substring. In other words, check whether there exists an index i such that the substring \(s[i \ldots i+|pattern|-1]\) is a permutation of pattern. The problem can be formally expressed as follows:

Given a string \(p\) (pattern) and a string \(s\) (text), determine if there exists an index \(i\) with \(0 \le i \le |s|-|p|\) such that the frequency distribution of the characters in \(s[i \ldots i+|p|-1]\) matches that of \(p\). If yes, output True, otherwise output False.

Note: Here, the permutation of a string simply refers to any reordering of its characters.

inputFormat

The input is read from standard input (stdin) and consists of two lines:

  1. The first line contains the pattern string \(p\).
  2. The second line contains the target string \(s\).

Both strings consist of lowercase English letters.

outputFormat

The output is a single line printed to standard output (stdout):

  • True if any permutation of the pattern exists as a substring in the text.
  • False otherwise.
## sample
ab
eidbaooo
True