#C1314. Permutation of Substring
Permutation of Substring
Permutation of Substring
You are given two strings, s and t. Your task is to determine whether there exists a substring in s that is a permutation of t. More formally, check if there exists an index \(i\) (with \(1 \le i \le |s| - |t| + 1\)) such that the substring \(s[i \ldots i+|t|-1]\) contains exactly the same characters (with the same multiplicity) as \(t\).
If such a substring is found, output YES
. Otherwise, output NO
.
inputFormat
The input consists of four lines:
- An integer \(n\) denoting the length of string s.
- A string s.
- An integer \(m\) denoting the length of string t.
- A string t.
Note that the lengths provided are consistent with the strings.
outputFormat
Output a single line containing either YES
or NO
based on whether there exists a substring of s that is a permutation of t.
10
cbabcacab
3
abc
YES