#K66497. Permutation Inclusion

    ID: 32433 Type: Default 1000ms 256MiB

Permutation Inclusion

Permutation Inclusion

Given two strings \( s_1 \) and \( s_2 \), determine if \( s_2 \) contains any permutation of \( s_1 \) as a contiguous substring. In other words, check if there exists a substring in \( s_2 \) which is an anagram of \( s_1 \).

For example, if \( s_1 = "ab" \) and \( s_2 = "eidbaooo" \), then output Yes because "ba", which is a permutation of "ab", is a substring of \( s_2 \). Conversely, if \( s_1 = "abc" \) and \( s_2 = "eidboaoo" \), output No because no permutation of "abc" exists in \( s_2 \).

The problem requires you to implement an efficient solution using a sliding window technique.

inputFormat

The input consists of two lines:

  • The first line contains the string \( s_1 \).
  • The second line contains the string \( s_2 \).

Note: Both strings consist only of lowercase English letters.

outputFormat

Output a single line containing either Yes if \( s_2 \) contains a permutation of \( s_1 \), or No otherwise.

## sample
ab
eidbaooo
Yes